Stw*_*eet 5 javascript arrays angularjs
嗨,它接缝像我不能推我的阵列?码:
$scope.arrResult = [];
dpd.timesheets.get( function (result) {
console.log(result);
for (i = 0, n = result.length; i < n; i++) {
var item = result[i];
$scope.arrResult[item.week].push(item);
}
console.log($scope.arrResult);
});
Run Code Online (Sandbox Code Playgroud)
我收到此控制台错误
Uncaught TypeError: Cannot read property 'push' of undefined
Run Code Online (Sandbox Code Playgroud)
如果我设置$scope.arrResult[item.week].push(item); to $scope.arrResult[item.week] = item;
它没有错误但我需要/想要推,但是错了吗?
Amm*_*CSE 11
这是因为
$scope.arrResult[item.week]
Run Code Online (Sandbox Code Playgroud)
本身不是一个数组.
push()是Array.prototype
看看我的意思,试试吧
$scope.arrResult[item.week] = [];
Run Code Online (Sandbox Code Playgroud)
要么
$scope.arrResult[item.week] = new Array();
Run Code Online (Sandbox Code Playgroud)
然后试试 push()
| 归档时间: |
|
| 查看次数: |
40130 次 |
| 最近记录: |