我有以下代码
var myctrl = function($scope) {
$scope.items = [{value: 1, name:'Nitin'},{value: 2, name:'Vikas'},{value: 3, name:'xxx'}];
$scope.itemEdit1 = $scope.items;
$scope.itemEdit2 = $scope.items.name;
};
我想只将名称复制到itemEdit2
答案 0 :(得分:1)
使用$scope.itemEdit2 = $scope.items[0].name;
如果您有兴趣复制所有名称,它应该是:
$scope.itemEdit2 = [];
$scope.items.forEach(function(v, i) {
$scope.itemEdit2.push({name: v.name}); // or just push(v.name);
});