2014-10-09 87 views
0

我是新來restangular,並試圖將其整合到我的應用程序。以下是我迄今所做的:restangular得到完整的JSON響應

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

我整理出來了。在我的應用程序配置

 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 
     )