【问题标题】:Ember select for belongsTo doesn't update hasMany end为 belongsTo 选择的 Ember 不更新 hasMany 结束
【发布时间】:2013-08-12 18:21:01
【问题描述】:

我正在尝试使用内置的 ember 选择视图更改 belongsTo。 However, when the select box changes only the belongs to attribute is updated, not the hasMany relationship.以下 jsbin 显示了这种行为 http://jsbin.com/ewosiy/3/edit

在这个例子中,一个人有很多事件,一个事件属于一个人。如果我更改了该事件的所属人,则该事件将从原来的人中删除,但不会添加到新的人中。

我可以滚动我自己的选择框组件,但只是想知道 ember 选择是否真的没有更新关系的两端。

谢谢。

【问题讨论】:

标签: ember.js ember-data


【解决方案1】:

为了让它工作,你需要在你的'person'对象的关系中使用'pushObject',你需要做这样的事情:

将您的选择更改为:

{{view Ember.Select
    contentBinding=controllers.application.model
    optionValuePath=content.id
    optionLabelPath=content.fullName
    selectionBinding=selectedPerson}}

并在你的 eventController 中添加:

selectedPersonChanged: function() {
  if(this.get('selectedPerson')) {
    this.get('selectedPerson.events').pushObject(this.get('content'));
  }
}.observes('selectedPerson')

【讨论】:

  • 完美。我只是很惊讶 ember 还没有处理这个案子。我将查看源代码,看看它是否使用了 pushObject。连接起来并不困难 =D。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
相关资源
最近更新 更多