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:
parent
b8454de57f
commit
246b4d70dc
@ -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];
|
||||
|
||||
|
16
test/runtime/samples/select-bind-in-array/_config.js
Normal file
16
test/runtime/samples/select-bind-in-array/_config.js
Normal 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' );
|
||||
}
|
||||
};
|
6
test/runtime/samples/select-bind-in-array/main.html
Normal file
6
test/runtime/samples/select-bind-in-array/main.html
Normal 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}}
|
Loading…
Reference in New Issue
Block a user