From 246b4d70dc26819a098c8670414ae7e812f360fb Mon Sep 17 00:00:00 2001 From: Yury Zhuravlev Date: Wed, 26 Jul 2017 11:37:06 +0900 Subject: [PATCH] Fix binding in each block --- src/generators/dom/visitors/Element/Binding.ts | 12 ++++++++++-- .../samples/select-bind-in-array/_config.js | 16 ++++++++++++++++ .../samples/select-bind-in-array/main.html | 6 ++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/select-bind-in-array/_config.js create mode 100644 test/runtime/samples/select-bind-in-array/main.html diff --git a/src/generators/dom/visitors/Element/Binding.ts b/src/generators/dom/visitors/Element/Binding.ts index b3c72fd608..945145cb64 100644 --- a/src/generators/dom/visitors/Element/Binding.ts +++ b/src/generators/dom/visitors/Element/Binding.ts @@ -87,8 +87,16 @@ export default function visitBinding( const { name } = getObject(attribute.value); const tailSnippet = getTailSnippet(attribute.value); - updateElement = deindent` - var ${value} = #component.get( '${name}' )${tailSnippet}; + if (state.inEachBlock === true) { + updateElement = deindent` + var ${value} = ${snippet}; + `; + } else { + updateElement = deindent` + var ${value} = #component.get( '${name}' )${tailSnippet}; + `; + } + updateElement += ` for ( var #i = 0; #i < ${state.parentNode}.options.length; #i += 1 ) { var ${option} = ${state.parentNode}.options[#i]; diff --git a/test/runtime/samples/select-bind-in-array/_config.js b/test/runtime/samples/select-bind-in-array/_config.js new file mode 100644 index 0000000000..609fc4592a --- /dev/null +++ b/test/runtime/samples/select-bind-in-array/_config.js @@ -0,0 +1,16 @@ +const items = [ { id: 'a' }, { id: 'b' } ]; + +export default { + 'skip-ssr': true, + + data: { + items + }, + + test ( assert, component, target ) { + const items = component.get('items'); + + assert.equal( items[0].id, 'a' ); + assert.equal( items[1].id, 'b' ); + } +}; diff --git a/test/runtime/samples/select-bind-in-array/main.html b/test/runtime/samples/select-bind-in-array/main.html new file mode 100644 index 0000000000..1a80b1afa0 --- /dev/null +++ b/test/runtime/samples/select-bind-in-array/main.html @@ -0,0 +1,6 @@ +{{#each items as item}} + +{{/each}}