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