如何在页面加载时为选择框设置默认选项?在下面的示例中,我尝试设置selectedPersonController的默认值,但没有成功。我做错什么了吗?
var App = Ember.Application.create();
App.Person = Ember.Object.extend({
id: null,
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName').cacheable()
});
App.selectedPersonController = Ember.Object.create({
person: null
});
App.peopleController = Ember.ArrayController.create({
content: [
App.Person.create({id: 1, firstName: 'Yehuda', lastName: 'Katz'}),
App.Person.create({id: 2, firstName: 'Tom', lastName: 'Dale'}),
App.Person.create({id: 3, firstName: 'Peter', lastName: 'Wagenet'}),
App.Person.create({id: 4, firstName: 'Erik', lastName: 'Bryn'})
]
});
模板:
{{view Ember.Select
contentBinding="App.peopleController"
selectionBinding="App.selectedPersonController.person"
optionLabelPath="content.fullName"
optionValuePath="content.id"}}
1条答案
按热度按时间o2g1uqev1#
您没有在
App.selectedPersonController
上设置特定人员。请参见以下工作示例:http://jsfiddle.net/ZpTYV/我不知道这是否是您的示例中的输入错误,但您还必须全局声明
App
,以便可以在Handlebars模板中访问它。