我需要添加元素,這是我得到的JSON格式轉換成數組作爲$ scope.array 我的代碼是:
$scope.sections=function(){
$scope.array=[];
$http.get("/app/query/?mod=find&type=all").success(function(data){
$.each(data, function(i, row){
$scope.array.push('aaa');
console.log(row);
});
});
return $scope.array;
}
console.log($scope.sections());
但這個函數返回空數組,我如何添加元素到$scope.array
?
此字符串將數據添加到正確康壽console.log(row);
,但$scope.array.push
是不行的
這是由於調用的異步性質。 – Chandermani
可能重複[如何從AJAX調用返回響應?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Stewie