我正在使用内置的ember选择视图来更改belongsTo。但是,当选择框更改只有属性属性被更新,而不是hasMany关系。以下jsbin显示此行为 jsbin/ewosiy/3/edit 。
I'm trying to change a belongsTo using the built in ember select view. However, when the select box changes only the belongs to attribute is updated, not the hasMany relationship. The following jsbin shows this behaviour jsbin/ewosiy/3/edit.
在这个例子中,一个人有许多事件和事件属于一个人。如果我更改了该事件属于哪个,则事件将从原始人员中删除,但从未添加到新人员。
In this example a person hasMany events and an event belongsTo a person. If I change who the event belongsTo, the event is removed from the original person but never added to the new person.
我可以滚动自己的选择框组件,但只是想知道Ember选择是否真的不会更新关系的两端。
I could roll my own select-box component but just wondered if the ember select really is not updating both ends of the relationship.
谢谢。
推荐答案为了使其工作,您需要在person对象的关系中使用pushObject,您需要执行以下操作:
in order to make it work, you need to use 'pushObject' in the relation of your 'person' object, you would need to do something like this:
将您的选择更改为:
{{view Ember.Select contentBinding=controllers.application.model optionValuePath=content.id optionLabelPath=content.fullName selectionBinding=selectedPerson}}并在你的eventController中添加以下内容:
and in your eventController add this:
selectedPersonChanged: function() { if(this.get('selectedPerson')) { this.get('selectedPerson.events').pushObject(this.get('content')); } }.observes('selectedPerson')更多推荐
Ember select for belongsTo不更新hasMany结束
发布评论