how to do binding in ember from some other class but the content is in another class with Ember.Select view
-
06-12-2019 - |
سؤال
I have used the following code:
{{view Ember.Select contentBinding="ResAdmin.adminController.priceCategories"
valueBinding="selectedRestaurant.PriceCategoryID"
optionLabelPath="content.name"
optionValuePath="content.id"}}
for creating select list...
from the collection:
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: "$$$$"
}
]
but i want to bind it to "selectedRestaurant.PriceCategoryID" Ember object..
How can i do it..
المحلول
You have to change valueBinding
to selectionBinding
, see http://jsfiddle.net/EwGbM/
Handlebars:
{{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);
لا تنتمي إلى StackOverflow