0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Fix binding in each block

This commit is contained in:
Yury Zhuravlev 2017-07-26 11:37:06 +09:00
parent b8454de57f
commit 246b4d70dc
3 changed files with 32 additions and 2 deletions

View File

@ -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];

View File

@ -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' );
}
};

View File

@ -0,0 +1,6 @@
{{#each items as item}}
<select bind:value="item.id">
<option value='a'>a</option>
<option value='b'>b</option>
</select>
{{/each}}