1

我从Ember 文档中获得了这个演示。它是一个分配了值的选择框。

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”项目。

当我将属性添加multiple="true"到 Ember.Select 时,“Tom”项仍处于选中状态。但我希望已经选择了多个项目,所以我改为App.currentProgrammer

App.currentProgrammer = [
  Ember.Object.create({id: 1}),
  Ember.Object.create({id: 2})
];

但是现在什么都没有选择了。我应该更改valueBinding- 属性吗?

4

1 回答 1

4

您可以使用 selectionBinding 代替:小提琴

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 仍然不起作用。

于 2013-07-11T09:31:43.913 回答