如何使用Ember.Select设置关联ID

时间:2012-03-10 20:35:34

标签: ember.js

我正在尝试使用Ember.Select控件在模型上设置关联ID。但是,我似乎无法将控件的选择绑定到id属性而不是整个模型对象。这是Ember.Select控件中的设计吗?我的模板中有以下内容:

  {{view Ember.Select
         contentBinding="App.peopleController.content"
         selectionBinding="App.selectedPersonController.personId"
         optionLabelPath="content.fullName"
         optionValuePath="content.id"}}

然而,即使将selectionBinding显式设置为personId属性,它仍然似乎绑定到person对象。完整的jsfiddle:http://jsfiddle.net/PXVZb/10/

1 个答案:

答案 0 :(得分:1)

我建议将所选人员绑定到您的App.selectedPersonController并创建一个与personId人绑定的属性id,参见http://jsfiddle.net/PXVZb/11/

JS:

App.selectedPersonController = Ember.Object.create({
    personIdBinding: 'person.id'
});

车把:

{{view Ember.Select
       contentBinding="App.peopleController.content"
       selectionBinding="App.selectedPersonController.person"
       optionLabelPath="content.fullName" }}