gpt4 book ai didi

angularjs推送对象未定义不是函数

转载 作者:行者123 更新时间:2023-12-03 07:57:39 24 4
gpt4 key购买 nike

所以,我有这个代码的问题,我不知道为什么我会收到那个错误

$scope.veilingen = {};
$http.get('./helpers/get/Veilingen.php').
success(function(data) {
if(debugMode) console.log(data);
$scope.veilingenCache = data;
for(var i = 0; i < 2; i++) {
console.log($scope.veilingen)
$scope.veilingen.push({
test: 'hello'
});
console.log($scope.veilingen)
}
});

我收到此错误:

TypeError: undefined is not a function at http://example.com/includes/controllers/veilingCntrl.js:12:30 at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:72 at I (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144) at I (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144) at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:101:308 at k.$eval (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:32) at k.$digest (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:109:121) at k.$apply (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:362) at h (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:327) at x (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:77:288)



第 12 行是 push() 区域。我已经搜索了为什么会发生这种情况,但我找不到它。我想要的是对象 veilingen 获得前 2 个结果,并且在加载后用户可以更改它:
$scope.setLimitVeiling = function(items) {
for(var i = 0; i < items; i++) {
$scope.veilingen.push($scope.veilingenCache[i]);
}
}

但是,是的,如果推送不起作用...?

最佳答案

$scope.veilingen被声明为一个对象而不是数组。

$scope.veilingen = [];

关于angularjs推送对象未定义不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25240691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com