2013-02-26 80 views
1

我从Ember documentation得到了这个演示。这是一个赋值的选择框。Ember.Select valueBinding与多个设置为true不起作用

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"}} 

这种情况的工作与 “汤姆” 被选中-Item。

当我将属性:multiple="true"添加到Ember.Select时,“Tom”-item仍处于选中状态。但我想这多个项目已经被选择,所以我改变App.currentProgrammer这样:

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

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

+0

在Github上有关于这个问题的请求:https://github.com/emberjs/ember.js/pull/996 – 2013-02-26 09:43:24

回答

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仍无法正常工作。

+1

valuebinding和selectbinding有什么区别? – user1952811 2014-07-13 01:57:27

+0

selectionBinding绑定整个内容,其中valueBinding仅绑定值部分,即optionValue – wallop 2014-11-06 10:51:03

相关问题