Ember-Model hasMany不保存模型emberjs [英] Ember-Model hasMany does not save model emberjs
本文介绍了Ember-Model hasMany不保存模型emberjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现这个
部门-HasMany->联系人。
I am trying to achieve this Department -HasMany->Contacts.
没有线索部门得到保存,但联系人没有得到保存
Have no clue Department gets saved but Contacts doesnt get Saved
您可以在jsbin中引用此部分
you can refer this section in jsbin
App.NewcontactController = Ember.ObjectController.extend({
needs: ['department'],
save: function () {
var department = this.get('controllers.department').get('model');
var newContact = App.Contact.create({
name: this.get('name'),
department: department
});
department.get('contacts').addObject(newContact);
console.log(department);
console.log(newContact);
department.get('contacts').save();
department.save();
console.log('---saved contact---');
this.transitionTo('contact',newContact);
}
});
Firebug LocalStorage
Firebug LocalStorage
Contact-1 "{"id":"1","department_id":"1"}"
Department-1 "{"id":"1","name":"A","contact_ids":[]}" //NO ids :(
更新
Ember-Model-LocalStorage的Ember模型
UPDATED Ember-Model with Ember-Model-LocalStorage
推荐答案
p>保存父级别不会保存子级。你有责任自己拯救孩子。 hasMany关系中有一个 save
方法,使其更容易一些。
Saving a parent doesn't save children. You are responsible for saving the children yourself. There is a save
method on the hasMany relationship to make this a little easier.
这篇关于Ember-Model hasMany不保存模型emberjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文