我試圖獲取數組的大小,但每次控制檯都說我未定義,並且不知道爲什麼。在Angular-JS中獲取數組大小
.success(function (data) {
console.log('Random-Suffix:' + suffix);
$scope.builds = new X2JS().xml_str2json(data);
var size = $scope.builds.length;
console.log('Size: ' + size);
$timeout(function() {
$scope.exampleLiveDataChange();
}, 3000);
})
'console.log($ scope.builds)'的輸出是什麼? – Manwal 2015-03-31 08:48:16
嘗試'console.log(typeof($ scope.builds))''你很可能會看到'$ scope.builds'不是一個數組!您可能需要輸出它並在其中查找您的數組; – Fourat 2015-03-31 09:07:20