Angularjs用对象数组推?

时间:2014-04-07 18:59:37

标签: angularjs push

我是angularjs的新手并尝试使用应用程序。我正在尝试创建加载更多功能,并将.push()与scope元素一起使用。

如何将以下数据中的帖子推送到$ scope变量? 请检查下面控制器中的代码。

{
"status": 200,
"result": {
    "success": true,
    "message": [
        {
            "offset": 6,
            "load_more": true,
            "brand_name": "HARLEY DAVIDSON",
            "posts": [
                {
                    "postID": 41,
                    "post_title": "DYNA STREET BOB (FD2) (FXDB)",
                    "engine_size": "1584 ccm",
                    "year": "2007-2013"
                },
                {
                    "postID": 43,
                    "post_title": "DYNA FAT BOB (FXDF)",
                    "engine_size": "1584 ccm ",
                    "year": "2008-2012"
                },
                {
                    "postID": 46,
                    "post_title": "Bike 1",
                    "engine_size": "1584 ccm ",
                    "year": "2008-2012"
                },
                {
                    "postID": 47,
                    "post_title": "Bike 2",
                    "engine_size": "1584 ccm ",
                    "year": "2008-2012"
                },
                {
                    "postID": 48,
                    "post_title": "Bike 3",
                    "engine_size": "1584 ccm ",
                    "year": "2008-2012"
                },
                {
                    "postID": 49,
                    "post_title": "Bike 4",
                    "engine_size": "1584 ccm ",
                    "year": "2008-2012"
                }
            ]
        }
    ]
},
"timestamp": 1396896763

}

这是控制器中的代码:

$scope.bikes = [];

Restangular.all('bikes/getBikesByTermId/' + $stateParams.termID+'/'+$scope.offset).getList().then(function (data) {
    $scope.term_title = data[0].brand_name;
    $scope.bikes = data[0].posts;
    $scope.offset = data[0].offset;
    $scope.load_more = data[0].load_more;
    $scope.isLoading = 0;
});

$scope.loadMore = function(){
    Restangular.all('bikes/getBikesByTermId/' + $stateParams.termID+'/'+$scope.offset).getList().then(function (data) {
        $scope.term_title = data[0].brand_name;
        $scope.bikes.push(data[0].posts);
        $scope.offset = data[0].offset;
        $scope.load_more = data[0].load_more;
        $scope.isLoading = 0;
    });
};

0 个答案:

没有答案