我必須建立一個angularjs客戶端的API輸出JSON是這樣的:如何處理分頁和計數與angularjs資源?
{
"count": 10,
"next": null,
"previous": "http://site.tld/api/items/?start=4"
"results": [
{
"url": "http://site.tld/api/items/1.json",
"title": "test",
"description": "",
"user": "http://site.tld/api/users/4.json",
"creation_datetime": "2013-05-08T14:31:43.428"
},
{
"url": "http://site.tld/api/items/2.json",
"title": "test2",
"description": "",
"user": "http://site.tld/api/users/1.json",
"creation_datetime": "2013-05-08T14:31:43.428"
},
{
"url": "http://site.tld/api/items/3.json",
"title": "test3",
"description": "",
"user": "http://site.tld/api/users/2.json",
"creation_datetime": "2013-05-08T14:31:43.428"
}
]
}
我怎樣才能使一個$resource
映射到這一點?如果我使用isArray=false
,我會將整個blob作爲一個對象,可用於閱讀,但我無法撥打.put()
。如果我使用isArray
,它只是不起作用。
有沒有乾淨的方法來做到這一點?或者我應該回去使用$http
?
TransformResponse是我需要的,thx。 – 2013-05-09 17:43:41
@joakimbl,你有什麼想法如何獲得下一個,以前或計數值?我的問題和上面提到的一樣,你的解決方案正是我需要的,唯一的問題是我使用'count'來呈現分頁器,所以我需要以某種方式獲得它的值。 – Sergey 2013-11-28 15:55:22
那麼,你可以在transformResponse函數中獲取它們(例如JSON.parse(data).count) - 但我不確定你會如何通過它們。您應該使用$ http服務。 – joakimbl 2013-11-30 10:33:54