我的范围如下
$scope.phones = [
{
id: 4,
name: "nokia",
accessories: [
{id: 1, name: "headset"},
{id: 3, name: "keyboard"},
{id: 5, name: "charger"}
]
},
{
id: 5,
name: "samsung",
accessories: [
{id: 5, name: "charger"}
]
},
{
id: 6,
name: "iphone",
accessories: [
{id: 1, name: "headset"},
{id: 5, name: "charger"}
]
}
];
例如,它们显示为
-> Phone name
-> accesories
现在我的情况
如果我更新与手机相关的配件,我想更新显示的记录,但仅更新与更新的配件相关的记录。我不想更新整个操作视图,而只想更新与更新的附件绑定的记录
我怎样才能做到这一点 ?
// 编辑
我创建了一个手动解决方法
$scope.editAcc = function (idx) {
for(var i = 0; i < $scope.phones.length; i++) {
var tmpPhone = $scope.phones[i];
for(var j = 0; j < tmpPhone.accessories.length; j++) {
var acc = tmpPhone.accessories[j];
if(acc.id == idx) {
acc.name = acc.name + " Z";
}
}
}
// var acc = $scope.accessories[idx]; // acc.name = acc.name + "X"; };
但是IMO应该有一些功能可以做到这一点