我有以下JSbin,我正在尝试使用ember-data创建一个基本的订购系统。
http://jsbin.com/ibazom/4(在Darshan的第一次评论后更新)
每个订单都需要与客户联系,我知道我需要填充属性(qualifiedCustomers)以绑定到Ember.Select,但我不知道该在哪里做。
然后我需要用
更新订单/新模板{{view Ember.Select
contentBinding="eligibleCustomers"
optionLabelPath="content.name"
optionValuePath="content.id"
}}
我在去/我无法弄清楚的订单时也遇到错误
TypeError: Cannot read property 'length' of null
更新:App.Order.FIXTURES =[];
解决了上述错误。
来自http://discuss.emberjs.com/t/proper-way-to-populate-ember-select/1611
的交叉帖子答案 0 :(得分:2)
您可以使用needs
声明您的OrdersNewController
需要customers
控制器。另外,创建一个属性以帮助轻松地绑定该控制器。
App.OrdersNewController = Ember.ObjectController.extend({
needs: ['customers'],
eligibleCustomers: function() {
return this.get('controllers.customers');
}.property(),
});
在相应的Ember.Select
中,您需要绑定到selectedCustomer
之类的属性,以便在保存记录时使用。
{{view Ember.Select
contentBinding="eligibleCustomers"
valueBinding='selectedCustomer'
optionLabelPath="content.name"
optionValuePath="content.id"
}}
要使OrderNewController
工作,您必须在setupController
中为其指定一个新的订单对象,以便description
和其他属性对应于它的模型,因为它是ObjectController
1}}
App.OrdersNewRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('model', App.Order.createRecord({}));
}
});
最后在createUser
方法中,不推荐使用transitionTo
。您想要使用transitionToRoute
。
createUser: function() {
var model = this.get('model');
var selectedCustomer = this.get('selectedCustomer');
var customer = App.Customer.find(selectedCustomer);
model.set('customer', customer);
model.set('dateOfOrder', new Date());
model.save();
this.transitionToRoute('orders');
}
以下是更新后的jsbin