我正在使用包含选择视图修改的最新版本的 Ember 来提供选项组。它工作得很好,只是我似乎无法设置默认值。
我在这里有一个 jsFiddle:http: //jsfiddle.net/csprocket777/Ja77Z/
鉴于上面的小提琴,我将如何设置默认值?
我在这里的 jsFiddle 中插入了代码:
HTML
<script type="text/x-handlebars">
{{view Ember.Select
contentBinding=filterValues
optionLabelPath="content.label"
optionValuePath="content.id"
optionGroupPath="group"
selectionBinding=selectedFilterOption
}}
</script>
Javascript
App = Ember.Application.create();
App.ApplicationController = Ember.ArrayController.extend({
selectedFilterOption: Ember.Object.create({
label: "File Type",
id: "urltype",
group: "By Attributes"
}),
filterValues:function(){
var ret = [
Ember.Object.create({
label: "Unfiltered",
id: "id",
group: "By Attributes"
}),
Ember.Object.create({
label: "Alphabetical",
id: "label",
group: "By Attributes"
}),
Ember.Object.create({
label: "File Type",
id: "urltype",
group: "By Attributes"
}),
Ember.Object.create({
label: "Title",
id: "title",
group: "By Value"
}),
Ember.Object.create({
label: "Order",
id: "order",
group: "By Value"
})
];
return ret;
}.property()
});