如何追加到角JS JSON对象 [英] How to append to a json object in angular js
本文介绍了如何追加到角JS JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的一个对象 $ scope.releases = [{名:所有的舞台,活动:真正}];
我需要更多的数据追加到它
[
{名:发展,活动:假},
{名:生产,活动:假},
{名:转移,积极的:假}
]
因此,最终数据应该是这样的。
[
{名:所有的舞台,活动:真正}
{名:发展,活动:假},
{名:生产,活动:假},
{名:转移,积极的:假}
]
我尝试以下code。但它不是追加。
app.controller('MainCtrl',函数($范围){
//我有一个像这样的对象
$ scope.releases = [{名:所有的舞台,活动:真正}];
//我需要更多的数据appned吧
$ scope.releases = [
{名:发展,活动:假},
{名:生产,活动:假},
{名:转移,积极的:假}
]
});
Pluker链接: http://plnkr.co/edit/gist:3510140
解决方案
$ scope.releases = [{名:所有的舞台,活动:真正}];
//并置新的数组到原来的
$ scope.releases = $ scope.releases.concat([
{名:发展,活动:假},
{名:生产,活动:假},
{名:转移,积极的:假}
]);
I am having an object like this $scope.releases = [{name : "All Stage",active:true}];
I need to append more data to it
[
{name : "Development",active:false},
{name : "Production",active:false},
{name : "Staging",active:false}
]
So the final data should be like this
[
{name : "All Stage",active:true}
{name : "Development",active:false},
{name : "Production",active:false},
{name : "Staging",active:false}
]
I tried the following code. But it is not appending.
app.controller('MainCtrl', function($scope) {
// I am having an object like this
$scope.releases = [{name : "All Stage",active:true}];
// I need to appned some more data to it
$scope.releases = [
{name : "Development",active:false},
{name : "Production",active:false},
{name : "Staging",active:false}
]
});
Pluker Link : http://plnkr.co/edit/gist:3510140
解决方案
$scope.releases = [{name : "All Stage",active:true}];
// Concatenate the new array onto the original
$scope.releases = $scope.releases.concat([
{name : "Development",active:false},
{name : "Production",active:false},
{name : "Staging",active:false}
]);
这篇关于如何追加到角JS JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文