1

当我继承 Ember.Select 时,选择绑定可以成功设置为控制器'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);
4

1 回答 1

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 上提交票证。

于 2012-04-25T21:51:48.943 回答