我是restangular的新手并尝试将其集成到我的应用中。这是我到目前为止所做的:
MyResource.getList(params).then((dt) ->
console.log dt
)
如果我使用$http.get
,那么我会获得完整的json对象
{
"param" : "a",
"param2" : "b",
"data": [
{
"id": 6,
"name": "v1",
"address": "some long address"
},
{
"id": 8,
"name": "vadsf",
"address": "some long address again"
},
{
"id": 13,
"name": "asdf",
"address": "another long address"
}
]
}
但是有了restangular,我会跟进:
[
{
"id": 6,
"name": "v1",
"address": "some long address"
},
{
"id": 8,
"name": "vadsf",
"address": "some long address again"
},
{
"id": 13,
"name": "asdf",
"address": "another long address"
}
]
如何才能获得完整的json而不仅仅是数据数组?
答案 0 :(得分:0)
我整理出来了。在我的app config
中 RestangularProvider.addResponseInterceptor((data, operation) ->
if operation is 'getList'
extractedData = data.data
if data.total then extractedData.param = data.param
if data.total then extractedData.param2 = data.param2
return extractedData
else data
)