我有以下的车型,客户设置一个属于关联属性的区域的下拉列表中的客户是 -通过行动控制器不工作
{{view Ember.Select viewName="select_area" content=possible_areas optionValuePath="content.id" optionLabelPath="content.name" value=area.id prompt="No area selected" selectionBinding="selected_area"}}
和控制器,其导线了一切一起 -
App.CustomerController = Ember.ObjectController.extend({
possible_areas: function() {
return this.store.find('area');
}.property(),
selected_area: null,
actions: {
save: function() {
var selected_area_id = this.get('selected_area.id');
console.log(selected_area_id);
var selected_area = this.store.find('area', selected_area_id);
var self = this;
selected_area.then(function(area) {
console.log(area.get('id'));
var updated_customer = self.get('model');
updated_customer.set('area', area);
console.log(new_customer.get('area.id'));
updated_customer.save()
.then(function(customer) {
//success
},
function() {
//failure
});
});
}
}
});
现在这里是奇怪的事情。当打电话的“拯救”行动的第一次,行updated_customer.set('area', area);
失败,错误
Uncaught Error: Assertion Failed: Cannot delegate set('id',) to the 'content' property of object proxy <DS.PromiseObject:ember551>: its 'content' is undefined.
当打电话“保存”后,立即采取行动,保存经过没有被成功更新客户的任何错误和地区。尽管下拉菜单显示selected_area为空。
如何防止第一次保存错误?
我使用的是ember-data 1.0.0-beta.6。
嗨菲克,谢谢你的答案。现在保存工作正常。但是,selectionBinding不起作用,因为它不显示选定的区域,无论是在第一次加载下拉菜单时还是在选择新值之后。它总是显示“No area selected”的提示。我尝试添加'value = area.id',但仍然没有正确显示选定的区域。 保存方法仍然得到正确的区域,虽然奇怪。 – KaranK
检查我的编辑。我有一种感觉,这是一个时间问题。 – Feech
我按照您的指定更改了路线。同样的问题。 – KaranK