我有一个对象列表,我想要通过某个键值插入每个对象。请注意它是AngularJS $scope
。我知道这可以通过。
以下是代码:
$scope.Items = [
{name:'Jani',country:'Norway'},
{name:'Hege',country:'Sweden'},
{name:'Kai',country:'Denmark'},
];
但我想要的是从那个到现在:
$scope.Items = [
{name:'Jani',country:'Norway', edit:false},
{name:'Hege',country:'Sweden', edit:false},
{name:'Kai',country:'Denmark', edit:false},
];
答案 0 :(得分:4)
一个简单的forEach
或几乎任何其他循环结构都可以做到:
$scope.Items.forEach(function(entry) {
entry.edit = false;
});