我正在使用 Ember-Data Rest-Adapter,从我的服务器返回的 JSON 看起来基本上像Active Model Serializers 文档中的那个
{
"meta": { "total": 10 },
"posts": [
{ "title": "Post 1", "body": "Hello!" },
{ "title": "Post 2", "body": "Goodbye!" }
]
}
从服务器获取数据是可行的,但不幸的是我无法弄清楚我可以从我的 JSON 响应中访问元信息的位置。
根据我对 ember-data 的 github issue 的研究,对元信息的支持似乎是通过 commit 1787bff实现的。
但即使有测试用例,我也无法弄清楚如何访问元信息。
App.PostController = Ember.ArrayController.extend({
....
requestSearchData: function(searchParams){
posts = App.Post.find(searchParams);
this.set('content', posts);
// don't know how to access meta["total"]
// but I want to do something like this:
// this.set('totalCount', meta["total"])
}
})
你们中的任何人都可以为我解释一下吗?我知道 Ember api 正在快速发展,但我确信我只是遗漏了一小部分,这实际上是可能的。