如何使用Ember.Select在分组模式下设置默认选择?

时间:2013-07-29 13:58:05

标签: javascript ember.js

我正在使用包含Select视图修改的最新版本的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()
});

1 个答案:

答案 0 :(得分:0)

您需要做的就是为value设置Ember.Select,例如:

<script type="text/x-handlebars">
{{view Ember.Select
  contentBinding=filterValues
  optionLabelPath="content.label"
  optionValuePath="content.id"
  optionGroupPath="group"
  selectionBinding=selectedFilterOption  
  value="title"
}}
</script>

如果您愿意,可以是valueBinding