2012-04-25 32 views
1

當我子類Ember.Select選擇綁定可以成功設置爲'content.selection'其中content是一個控制器。當我嘗試在模板中內聯執行此操作時,綁定不會連接。這個問題可以看出,在這個演示:http://jsfiddle.net/cmQsX/爲什麼Ember.Select上的selectionBinding不尊重contentBinding,當Ember.Select不是子類時?

模板:

<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); 

回答

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