使用Angularjs范围

时间:2015-12-01 19:32:14

标签: javascript angularjs angularjs-scope angular-resource

我有以下函数来获取$resourse的数据,我想将输出数据与$scope.data合并。

console.log(sasa) print

[$promise: Promise, $resolved: false]
    Resource1:
    Resource2:
    Resource3: 
    Resource4: 
    Resource5:
    $promise: Promise
    $resolved: true
    length: 5
    __proto__: Array[0]

console.log($scope.data); print null

$scope.data=[]
function getData(){
    var sasa= $resource('api/testrecordajaxs/:page/:size', {
            page : page,
            size : size
    }).query();
    $scope.data.push.apply($scope.data,sasa);
    console.log(sasa)
    console.log($scope.data);
    return $scope.data;
}

2 个答案:

答案 0 :(得分:0)

您可以使用.concat合并两个数组

$ scope.mergedArray = $ scope.data.concat(输出);

答案 1 :(得分:0)

您还没有足够的信息让我100%确定,但看起来您正在尝试从对象中读取所有键,而不是数组的所有值。这真的是你需要的。

THIS

" // $scope.data = [] var $scope = { data: [] } // initialization just for this demo //function getData(){ //var sasa= $resource('api/testrecordajaxs/:page/:size', { // page : page, // size : size //}).query(); // it looks to me like this isn't even an array in your example. var sasa = { Resource1: 1, Resource2: 2, Resource3: 3, Resource4: 4, Resource5: 5 }; //$scope.data.push.apply($scope.data,sasa); // THIS is what you want for (var key of Object.keys(sasa)) { $scope.data.push(sasa[key]); } console.log($scope.data); // return $scope.data; //}"全部大写



return json.dumps(data, indent=4, default=json_util.default)