且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在现有的角JS阵列添加新的关键?

更新时间:2023-12-02 22:08:52

就地阵列上运行。简单

  $ scope.order = [];
$ scope.itemDetails =功能(){
    //这里得到的数据形式submiti后有阵列从形式arrieve提交。
    $ scope.order.push({名:$ scope.item.name,价格:$ scope.item.price});
}

(不分配的话),而应该努力!

I have define blank array $scope.order, ON form submit data get and create new array then merge with existing array.

.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});
    }
});

I want result like this.

$scope.order = [{name:'abc',price:100},{name:'pqr',price:80},{name:'xyz',price:50}];

When itemDetails() call at that time array merge with new data.

push operates on the array in-place. Simply

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

(without assigning it), and that should work!