【发布时间】:2013-12-20 01:58:37
【问题描述】:
我正在使用带有 API 的 Ember.js (v1.2.0),它返回分页的 JSON 数据,如下所示:
{
"count": 5,
"next": "http://127.0.0.1:8000/some/resource/?page=2",
"previous": null,
"results": [
{
"id": 37,
"title": "Some title",
"description": "Some description",
},
{
"id": 35,
"title": "Sdflskdf",
"description": "sdfkdsjf",
},
{
"id": 34,
"title": "Some other title",
"description": "Dsdlfksdf",
},
]
}
我不使用 ember-data,所以我使用一个普通的 ember 对象作为我的模型并像这样加载数据:
App.SomeResource = Ember.Object.extend({});
App.SomeResource.reopenClass({
find: function () {
return $.getJSON('/some/resource/').then(function (response) {
return response.results.map(function (data) {
return App.SomeResource.create(data);
});
});
},
});
我的模型类的 find 方法返回一个解析为对象数组的 promise。在创建 SomeResource 对象时,所有的分页数据都会丢失。
当承诺解决时,有没有办法在某处存储 count、next 和 previous 页面网址?
【问题讨论】:
标签: ember.js model pagination promise