使用$resource来访问Rest资源的时候遭遇了一个诡异的bug,想要获取的数据是一个嵌套数组,但返回结果中的子数组全部都被转换成对象了,然后对数据的操作有一个流程依赖于数组长度来进行判断,就失效了,直接导致数据没有成功更新到视图上。
- 部分代码:
$resource('rest/overview_statistics/Count',
{
startDate: $scope.startDate,
endDate: $scope.endDate
}).query(function (result) {
instance.deleteEveryEndpoint();
.....
var status = [], copy = $scope.data.slice();
while (copy.length > 0) {
var tmp = copy.shift();
while (tmp.length > 0) {
var _p = tmp.shift();
status.push(_p.status);
}
}
.....
})
}, function (err) {
......
});
![](https://img.haomeiwen.com/i3242313/d5b936e247a7724d.png)
![](https://img.haomeiwen.com/i3242313/f7cf9e155b08c7b6.png)
搜索了一下,原因大概是:
![](https://img.haomeiwen.com/i3242313/01e45bece1553e77.png)
参考资料
网友评论