如何在角度js中添加现有数组中的新键?

时间:2015-06-04 05:22:51

标签: javascript arrays angularjs angularjs-scope

我已定义空数组$ scope.order,ON表单提交数据获取并创建新数组然后与现有数组合并。

.controller('GuestDetailsCtrl',function($scope){
    $scope.order = [];
    $scope.itemDetails = function() {
        // Here data get after form submiti have array arrieve from form submit.
        $scope.order=$scope.order.push({name:$scope.item.name,price:$scope.item.price});
    }
});

我想要这样的结果。

  

$ scope.order = [{name:' abc',price:100},{name:' pqr',price:80},{name:' XYZ',价格:50}];
  
  当itemDetails()调用时,数组与新数据合并。

1 个答案:

答案 0 :(得分:2)

.animatedDiv { width: 820px; height: 312px; background-image: url("https://cf.dropboxstatic.com/static/images/index/animation-strips/hero-intro-bg-vflR5rUow.jpg"); -webkit-animation: play 2s steps(48) infinite; -moz-animation: play 2s steps(48) infinite; -ms-animation: play 2s steps(48) infinite; -o-animation: play 2s steps(48) infinite; animation: play 2s steps(48) infinite; } @-webkit-keyframes play { from { background-position: 0px; } to { background-position: -39360px; } } @-moz-keyframes play { from { background-position: 0px; } to { background-position: -39360px; } } @-ms-keyframes play { from { background-position: 0px; } to { background-position: -39360px; } } @-o-keyframes play { from { background-position: 0px; } to { background-position: -39360px; } } @keyframes play { from { background-position: 0px; } to { background-position: -39360px; } } 就地对阵列进行操作。简单地

push

(没有指定),这应该有效!