在对象中创建对象数组 - Node.js

时间:2017-04-07 04:56:14

标签: angularjs node.js angular

在下面的代码中,'info'对象有描述,数量,值。如何将它们作为数组(Indo属性)。如何检索角度代码。

details.customsDetail.itemDetails = {
                    currency : "2000USD",
                    weight : "lbs",
                    info : {                         
                        description : "descr",
                        quantity : "2",
                        value : "124",              

                     }

            };

2 个答案:

答案 0 :(得分:3)

你的意思是,indo属性作为对象数组吗?

details.customsDetail.itemDetails = {
                    currency : "2000USD",
                    weight : "lbs",
                    info : [{                         // How to give this in a array.
                        description : "descr",
                        quantity : "2",
                        value : "124",              

                     }]

            };

答案 1 :(得分:1)

您可以将对象分配给变量,然后可以将其推送到数组。

var backUp = angular.copy($scope.details.customsDetail.itemDetails.info);

$scope.details.customsDetail.itemDetails.info = [];
$scope.details.customsDetail.itemDetails.info.push(backUp);

console.log($scope.details.customsDetail.itemDetails)



angular.module("app",[])
.controller("ctrl",function($scope){
$scope.details = {"customsDetail":{"itemDetails":{}}};

$scope.details.customsDetail.itemDetails = {
      currency : "2000USD",
      weight : "lbs",
      info : {// How to give this in a array.
          description : "descr",
          quantity : "2",
          value : "124",              

       }

  };

var backUp = angular.copy($scope.details.customsDetail.itemDetails.info);

$scope.details.customsDetail.itemDetails.info = [];
$scope.details.customsDetail.itemDetails.info.push(backUp);

console.log($scope.details.customsDetail.itemDetails)
  
})

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 
</div>
&#13;
&#13;
&#13;