0
我得到這個錯誤,我試過幾個東西,但沒有工作,這是我的ResponseInterceptor反應應該是一個數組,在我restangular項目不是一個對象或別的東西restangular
restangularProvider.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
if (operation == "getList") {
var responseData = response.data;
if (responseData.paginginfo == undefined) return responseData;
return { pagingInfo: responseData.paginginfo, data: responseData.result };
}
if (operation != "get") {
var item = { status: response.status };
feedBackFactory.showFeedBack(item);
}
return response.data;
});
}]);
我我使用的Web API,代碼如下
[Route("")]
[HttpGet]
public IHttpActionResult Get(int page, int size)
{
var paginginfo = new PagingModel { CurrentPage = page, RecordsPerPages = size };
var result = _userManagementService.Getusers(paginginfo);
if (result.Count == 0) return NotFound();
return Ok(new { result, paginginfo});
}
樣本數據給出的從我的API是
{"result":[{"id":"d615bf59-d089-e411-8295-a0481ca19571","firstname":"binson","lastname":"eldhose","username":"binson143","email":"[email protected]","mobile":"9846369298","userkey":"emp-009","notes":"binson","password":null,"image":"noimage.jpg","createdDate":"2014-12-22T14:47:48.407","status":"Active"},{"id":"0a79c171-c189-e411-8295-a0481ca19571","firstname":"jomon","lastname":"rv","username":"[email protected]","email":"[email protected]","mobile":"9876543478","userkey":"emp-007","notes":"good progtam","password":null,"image":"noimage.jpg","createdDate":"2014-12-22T13:01:06.817","status":"Active"},{"id":"f02053ff-b989-e411-8294-a0481ca19571","firstname":"Mohit","lastname":"Sarma","username":"[email protected]","email":"[email protected]","mobile":"9867564534","userkey":"Emp-008","notes":"A good programmer too","password":null,"image":"noimage.jpg","createdDate":"2014-12-22T12:07:48.35","status":"Active"},{"id":"e69a316c-bf89-e411-8295-a0481ca19571","firstname":"nizar","lastname":"kp","username":"nizar143","email":"[email protected]","mobile":"98675645321","userkey":"emp-009","notes":"good programmer","password":null,"image":"noimage.jpg","createdDate":"2014-12-22T12:46:38.023","status":"Active"},{"id":"5c2e3ede-b989-e411-8294-a0481ca19571","firstname":"Rins","lastname":"Dominc","username":"rins143","email":"[email protected]","mobile":"98675654345","userkey":"Emp-001","notes":"Good employee","password":null,"image":"noimage.jpg","createdDate":"2014-12-22T12:06:52.85","status":"Active"}],"paginginfo":{"currentPage":1,"totalRecords":5,"recordsPerPages":10,"startRecord":1,"endRecord":5,"totalPages":1}}
什麼768,16我重寫這個錯誤,請沒有我不能改變像
return Ok(new object[] { result, paginginfo});
退房這樣的回答: http://stackoverflow.com/questions/22012655/restangular-getlist-with-object-containing-embedded-array – MichaelLo
@MichaelLo首先嚐試,但沒有工作......如果你的getList方法返回的是對象而不是數組,使用customGET方法,我正在使用retangular 1.4 –
。 customGET將允許您返回對象而不是數組。 – dhavalcengg