Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json EmberJS数据具有多个关系父jon包含整个对象而不是ID_Json_Ember.js_Ember Data_Has Many - Fatal编程技术网

Json EmberJS数据具有多个关系父jon包含整个对象而不是ID

Json EmberJS数据具有多个关系父jon包含整个对象而不是ID,json,ember.js,ember-data,has-many,Json,Ember.js,Ember Data,Has Many,EmberJS数据具有多个关系父JSON包含整个对象而不是ID App.Message = someParentClass.extend({ childMessages: DS.hasMany('ChildMessage'), message:DS.attr('string',{defaultValue: ""}) } App.ChildMessage = someParentClass.extend({ message: DS.attr('string',{defau

EmberJS数据具有多个关系父JSON包含整个对象而不是ID

App.Message = someParentClass.extend({
    childMessages: DS.hasMany('ChildMessage'),
    message:DS.attr('string',{defaultValue: ""})
}

App.ChildMessage = someParentClass.extend({
    message: DS.attr('string',{defaultValue: ""}),
    code:DS.attr('string',{defaultValue: ""})
}
JSON看起来像这样

{
    "message":"xyz",
    "childMessages":[{"code":"we","message":""},{"code":"uh","message":""},{"code":"wd","message":""}]
}
获取对象后,子消息的代码和消息未定义(未填充)

正在更改JSON而不是在我手中


请帮助解决问题

余烬需要每个子对象的id。所以我从服务器添加了带有随机数的id文件

{
    "message":"xyz",
    "childMessages":[{"id":4567,"code":"we","message":""},{"id":7874,"code":"uh","message":""},{"id":5231,"code":"wd","message":""}]
}
它起作用了


谢谢

您使用的是什么版本的余烬和余烬数据?此外,对象不包含ID这一事实也有问题。例如,在保存时,ember data如何知道哪些对象已被修改?您的应用程序是否只需要从API读取数据,还是必须同时保存?谢谢@Oren您的评论