【问题标题】:Ember.Select valueBinding with multiple set to true doesn't work多个设置为 true 的 Ember.Select valueBinding 不起作用
【发布时间】:2013-02-26 09:26:08
【问题描述】:

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

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

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

但现在没有任何选择。我应该更改valueBinding-属性吗?

【问题讨论】:

标签: ember.js


【解决方案1】:

您可以使用 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 仍然不起作用。

【讨论】:

  • 值绑定和选择绑定有什么区别?
  • selectionBinding 绑定整个内容,而 valueBinding 仅绑定值部分,即 optionValue
猜你喜欢
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
  • 1970-01-01
  • 2015-09-12
  • 2016-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多