2014-04-28 140 views
0

使用Ember.Select,我成功地使我的下拉菜單Ember.Select - 選擇價值

{{view Ember.Select 
    content=businessType.acceptableValues 
    optionLabelPath="content.name" 
    optionValuePath="content.value" 
    prompt=businessType.prompt 
}} 

從模型中把數據控制器看起來像:

businessType: function(){ 
     var content = this.get('content'); 
     return content.get(10); 
    }.property('content') 

我可以」弄清楚如何設置選定的值。我試圖設置值content.value,我試過selectionBinding = content.value,但沒有任何工作對我來說。我對此沒有理解。

謝謝

回答

0

看看http://emberjs.com/api/classes/Ember.Select.html文件。

它說:

一個Ember.Select 內選擇的值屬性可以被綁定到一個屬性上的另一個目的:

App.ApplicationController = Ember.Controller.extend({ 
    programmers: [ 
    {firstName: "Yehuda", id: 1}, 
    {firstName: "Tom", id: 2} 
    ], 
    currentProgrammer: { 
    id: 2 
    } 
}); 

{{view Ember.Select 
     content=programmers 
     optionValuePath="content.id" 
     optionLabelPath="content.firstName" 
     value=currentProgrammer.id}} 

通過選擇與所繪製的元件相互作用第一個選項 ('Yehuda')將更新currentProgrammer的id以匹配新選擇的值 屬性。

所以你只需要綁定一些現有的對象屬性到Ember.Select value

+0

瞭解。因此,如果我將該示例附加到currentProgrammer:{id:2}到我的控制器,然後在Ember.Select中添加value = currentProgrammer.id,我會認爲它會起作用。但事實並非如此。這裏有一個https://gist.github.com/bungdaddy/11361635 – Bungdaddy

+0

你能用你的代碼準備一個jsbin嗎? –