我正在尝试设置生成的选择框的默认选定值,{{view Em.Select}}
根据文档设置valueBinding
为适当的值或selecitonBinding
由项目表示的完整对象,这应该是一项非常简单的任务。
示例代码:http: //jsfiddle.net/p2dtx/2/
HTML
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
!{{dafaultOption}}!
{{view Em.Select prompt="test" contentBinding="controllers.option.content" optionLabelPath="content.name" optionValuePath="content.id" valueBinding="dafaultOption" }}
</script>
JS
App = Ember.Application.create();
App.Store = DS.Store.extend({
adapter: DS.FixtureAdapter
});
App.Router.map(function() {
// put your routes here
});
App.IndexController = Em.Controller.extend({
dafaultOption: 'OP2',
needs:['option']
});
App.Option = DS.Model.extend({
name: DS.attr('string')
});
App.Option.FIXTURES = [
{
id: 'OP1',
name: 'Option 1'
},
{
id: 'OP2',
name: 'Option 2'
}
];
App.OptionController = Em.Controller.extend({
init: function() {
this._super();
this.set('model', this.get('store').find('option'))
}
})
注意页面加载之间的值!! 为空,尽管defaultOption
在 IndexController 声明中设置为“OP2”。如果我从OP2 中删除该valueBinding
选项,则在 !! {{view Em.Select}}
as expected, which leads me to believe that when the select is being rendered it is setting the indexController.defaultOption
to null (prompt option). 当我手动更改选择时,值会按预期更新。有任何想法吗?