簡體   English   中英

ember.js-hasMany / belongsTo關系不會更新父模型

[英]ember.js - hasMany/belongsTo Relation doesn't update parent model

無法解決此問題,但這似乎是一年前的一個正式錯誤,但已經關閉了……所以也許我只是想念一些東西。

我創建了一個子級,但我的父級模型在客戶端和服務器上均未更新。

我的模特:

var attr = DS.attr,
    hasMany = DS.hasMany,
    belongsTo = DS.belongsTo;
App.User = DS.Model.extend({
    name: attr(),
    email: attr(),
    hash: attr(),
    lists: hasMany('list')
})
App.List = DS.Model.extend({
    user: belongsTo('user'),
    name: attr(),
    desc: attr(),
    items: hasMany('item')
})
App.Item = DS.Model.extend({
    list: belongsTo('list'),
    name: attr(),
    desc: attr()
})

我如何創建孩子:

addList: function(){
    var list = this.store.createRecord('list', {
        name: 'New list',
        desc: 'Describe it here'
    });
    this.store.find('user', 1).then(function(user){
        list.set('user', user);
        list.save();
    })
}

也將孩子添加到父母中:

addList: function(){
    var list = this.store.createRecord('list', {
        name: 'New list',
        desc: 'Describe it here'
    });
    this.store.find('user', 1).then(function(user){
        list.set('user', user);
        user.get('lists').pushObject(list);
        list.save();
    })
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM