为什么当Ember.Select没有子类时,Ember.Select上的selectionBinding不尊重contentBinding?

时间:2012-04-25 20:28:22

标签: ember.js

当我将Ember子类化时。选择选择绑定可以成功设置为'content.selection',其中content是控制器。当我尝试在模板中内联时,绑定不会连接。在此演示中可以看到此问题:http://jsfiddle.net/cmQsX/

模板:

<script type="text/x-handlebars" >
    {{view Ember.Select contentBinding="ResAdmin.adminController" selectionBinding="content.selection" optionLabelPath="content.name" optionValuePath="content.id" }}
    {{view ResAdmin.foo}}

    Selected: {{ResAdmin.selectedRestaurant.priceCategory.name}}
</script>​

代码:

ResAdmin = Ember.Application.create({});

ResAdmin.adminController = Ember.ArrayProxy.create({
    selection: null,
    content: [
        {
        id: '92E9862E-DAE5-4CC8-ACDF-7E6418641F7D',
        name: "$"},
    {
        id: '889C0E73-1587-41D5-8073-FD29FF76CF00',
        name: "$$"},
    {
        id: '47A56B26-A64A-4967-A9F6-B9D69B2CA145',
        name: "$$$"},
    {
        id: '417993DB-48BF-4BA9-BE0A-D6A53C6D8325',
        name: "$$$$"}
    ],
    getObjectById: function(id) {
        return this.get('content').filterProperty('id', id).get('firstObject');
    }
});

ResAdmin.selectedRestaurant = Ember.Object.create({
    priceCategoryBinding: 'ResAdmin.adminController.selection'
});

ResAdmin.foo = Ember.Select.extend({
    contentBinding:"ResAdmin.adminController",
    selectionBinding:"content.selection",
    optionLabelPath:"content.name",
    optionValuePath:"content.id"})

var defaultItem = ResAdmin.adminController.getObjectById('47A56B26-A64A-4967-A9F6-B9D69B2CA145');
console.log(defaultItem);
ResAdmin.adminController.set('selection', defaultItem);

1 个答案:

答案 0 :(得分:2)

当您将选择指定为selectionBinding="ResAdmin.adminController.selection"时,它会起作用,请参阅http://jsfiddle.net/pangratz666/rXudx/

{{view Ember.Select
    contentBinding="ResAdmin.adminController"
    selectionBinding="ResAdmin.adminController.selection"
    optionLabelPath="content.name"
    optionValuePath="content.id" }}

这似乎是一个错误。您应该在GitHub上提交一张票。