How to append to a json object in angular js

后端 未结 3 440
名媛妹妹
名媛妹妹 2021-01-02 01:46

I am having an object like this $scope.releases = [{name : \"All Stage\",active:true}];

I need to append more data to it

[
  {name : \"         


        
相关标签:
3条回答
  • 2021-01-02 02:28

    Just use the Array concat method

    $scope.release = [{name : "All Stage",active:true}];
    $scope.releases = [
        {name : "Development",active:false},
        {name : "Production",active:false},
        {name : "Staging",active:false}
    ];
    $scope.releases = $scope.releases.concat($scope.release);
    
    0 讨论(0)
  • 2021-01-02 02:34

    user angular.extend() to extend the object angular extend

    you can also use angular.merge() angular merge

    0 讨论(0)
  • 2021-01-02 02:38
      $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}
      ]);
    
    0 讨论(0)
提交回复
热议问题