我使用了以下代码:
{{view Ember.Select contentBinding="ResAdmin.adminController.priceCategories"
valueBinding="selectedRestaurant.PriceCategoryID"
optionLabelPath="content.name"
optionValuePath="content.id"}}
用于创建选择列表...
来自收藏:
priceCategories: [
{
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: "$$$$"
}
]
但我想将它绑定到“selectedRestaurant.PriceCategoryID”Ember对象..
我该怎么做..
答案 0 :(得分:1)
您必须将valueBinding
更改为selectionBinding
,请参阅http://jsfiddle.net/EwGbM/
车把:
{{view Ember.Select contentBinding="ResAdmin.adminController"
selectionBinding="ResAdmin.adminController.selection"
optionLabelPath="content.name" }}
Selected: {{ResAdmin.selectedRestaurant.priceCategory.name}}
JS:
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'
});
var defaultItem = ResAdmin.adminController.getObjectById('47A56B26-A64A-4967-A9F6-B9D69B2CA145');
ResAdmin.adminController.set('selection', defaultItem);