Ember Data 2.1.0忽略了我的JSON响应中的links属性

时间:2015-10-09 13:24:58

标签: javascript ember.js ember-data

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')
});

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属性而不是相关属性。并且还与作为url的href属性的对象相关。

1 个答案:

答案 0 :(得分:2)

好的,我明白了。问题是数据属性。似乎如果它存在,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"
    }
  }
}