Ember Data 2.1.0 忽略我的 JSON 响应中的 links 属性并触发以下请求:
/point_logs/3e5ff053422f40e3a8057fc5e8100c47
此外,对于发现的每个点日志,它都会触发一个请求。相反,我希望它获取所有点日志的集合。
在 Ember 1.x 中,一切都运行良好。到处寻找答案,但不幸的是到目前为止我无法找到解决方案。
设备型号
var DirectObject = DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
type: DS.attr('string'),
createdDate: DS.attr('date'),
modifiedDate: DS.attr('date'),
deletedDate: DS.attr('date'),
pointLog: DS.belongsTo('pointLog')
});
点对数模型
var PointLog = DS.Model.extend({
unit: DS.attr('string'),
type: DS.attr('string'),
lastConsecutiveLogDate: DS.attr('date'),
updatedDate: DS.attr('date'),
directObject: DS.belongsTo('directObject')
});
JSON 响应
{
"data": [
{
"id": "6dbcf32a3e064a36a1db4847329cc90d",
"type": "appliance",
"attributes": {
"name": "3974737",
"description": "",
"type": "zz_misc",
"createdDate": "2015-09-15T14:23:02.768Z",
"modifiedDate": "2015-10-08T08:39:15.525Z",
"deletedDate": null
},
"relationships": {
"pointLog": {
"data": {
"id": "3e5ff053422f40e3a8057fc5e8100c47",
"type": "pointLog"
},
"links": {
"related": "/core/appliances/6dbcf32a3e064a36a1db4847329cc90d/point_log"
}
}
}
}
],
"included": [],
"links": {
"self": "/core/appliances"
}
}
我还尝试使用 self 属性而不是相关属性。并且还与一个对象相关,其中的 href 属性是 url。
最佳答案
好吧,我明白了。问题在于数据属性。看起来,如果它存在,Ember 将进行单独的调用,而不使用链接对象中给出的 url。
之前
"relationships": {
"pointLog": {
"data": {
"id": "3e5ff053422f40e3a8057fc5e8100c47",
"type": "pointLog"
},
"links": {
"related": "/core/appliances/6dbcf32a3e064a36a1db4847329cc90d/point_log"
}
}
}
之后
"relationships": {
"pointLog": {
"links": {
"related": "/core/appliances/6dbcf32a3e064a36a1db4847329cc90d/point_log"
}
}
}
关于javascript - Ember Data 2.1.0 忽略我的 JSON 响应中的 links 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33039477/