我从Ember documentation获得了此演示。这是一个分配了值的选择框。
App.programmers = [
Ember.Object.create({firstName: "Yehuda", id: 1}),
Ember.Object.create({firstName: "Tom", id: 2})
];
App.currentProgrammer = Ember.Object.create({
id: 2
});
查看:
{{view Ember.Select
contentBinding="App.programmers"
optionValuePath="content.id"
optionLabelPath="content.firstName"
valueBinding="App.currentProgrammer.id"}}
此案例有效并且选择了“Tom”-item。
当我将属性multiple="true"
添加到Ember.Select时,仍然选择“Tom”-item。但我希望已经选择了多个项目,因此我将App.currentProgrammer
更改为:
App.currentProgrammer = [
Ember.Object.create({id: 1}),
Ember.Object.create({id: 2})
];
但现在没有任何东西被选中了。我应该更改valueBinding
- 属性吗?
答案 0 :(得分:4)
您可以改为使用selectionBinding:Fiddle
HTML:
<script type="text/x-handlebars">
{{view Ember.Select
multiple="true"
contentBinding="App.content"
optionValuePath="content.type"
optionLabelPath="content.label"
prompt="Select a value"
selectionBinding="App.types"
}}
{{#each App.types}}
{{type}}
{{/each}}
</script>
JS:
App = Ember.Application.create({});
App.content = [
{label: "This is type 1", type: "type1"},
{label: "This is type 2", type: "type2"}
];
App.types = [
App.content[0], App.content[1]
];
我同意valueBinding仍无效。