json结构应该是什么ember-data“findmany”必须正确地侧进入吗?
-
12-12-2019 - |
题
我正在与ember-data一起做我的第一个有了的关系,并击中始终有趣
“未捕获的错误:断言失败:您的服务器返回了一个哈希 键0,但你没有映射“
这通常意味着我在我所谓的“ember”友好格式中我没有JSON结构。
我正在使用django休息框架构建我自己的休息适配器,所以我很好奇,这应该看起来像没有错误的情况。
目前,JSON回来看起来如下(显然没有绑在它的会话中,但也许ember已经知道如何加入这个?)
[{“ID”:2,“名称”:“foobar”}“
模型看起来像这个
.CodeCamp.Session = DS.Model.extend({ id: DS.attr('number'), name: DS.attr('string'), room: DS.attr('string'), desc: DS.attr('string') }); CodeCamp.Speaker = DS.Model.extend({ id: DS.attr('number'), name: DS.attr('string'), session: DS.belongsTo('CodeCamp.Session') }); CodeCamp.Session.reopen({ speakers: DS.hasMany('CodeCamp.Speaker') });
提前谢谢
解决方案
JSON结构应该看起来像这个
{ speakers: [{ id: 2, name: "FooBar" }] }
.
发现此提交显示我只需要在一个名为dict 中缠绕我的JSON。
https://github.com/kurki/data/commit/f59ad5bc9718634b6f3d59356deae0bf97a1bbd5
所以这是我现在在我的django适配器中的自定义JSON方法
findMany: function(store, type, ids) {
var root = this.rootForType(type), plural = this.pluralize(root), json = {};
this.django_ajax(this.buildURL(root, ids), "GET", {
success: function(pre_json) {
json[plural] = pre_json;
this.sideload(store, type, json, plural);
store.loadMany(type, json[plural]);
}
});
}
. 不隶属于 StackOverflow