$resource 奇遇记

2017-08-12  本文已影响0人  假装会编程

使用$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) {
          ......
      });
resource拿到的数据 响应中的数据格式

搜索了一下,原因大概是:

resource限制

参考资料

上一篇 下一篇

猜你喜欢

热点阅读