2017-04-07 35 views
0

在下面的代碼中,'info'對象具有描述,數量,值。如何將它們作爲數組(Indo屬性)。如何在角碼中檢索。在對象中創建對象數組 - Node.js

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

        } 

      }; 
+0

什麼叫'如何給這個在array.'是什麼意思? –

回答

3

你的意思是,indo屬性作爲數組的對象嗎?

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

        }] 

      }; 
+0

是的。如何在角碼中檢索這個? – Anju

+0

在Angular代碼中檢索是什麼意思? – Ved

+0

感謝您的幫助。我知道了。 – Anju

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>