javascript - 删除嵌套数组Angular 2/4中的对象行
问题描述
我有一个模型,它在对象数组中包含数组:
<div *ngFor="let n of shops?.locations let i=index;">
<span>{{n.name}}</span>
<button (click)="select(n, i)">select</button>
</div>
<popup>
<div *ngFor="let subloc of locationssub let j=index;">
<span>{{subloc.id}}</span>
<span><{{subloc.name}}</span>
<button (click)="delete(subloc, j)">del</button>
</div
</popup>
在我的组件中,我有:
select(n, i){
this.indexi=i;
this.locationssub=n;
this.popup.show();
}
delete(subloc, j){
this.shops.locations[this.indexi].locationssub.splice(j,1);
}
当我运行它时,它不会拼接和删除该行。
我该如何解决?
解决方案
您好,有两个可能的原因。
- 您的代码不起作用(是从您的数组中删除的条目)
- Angular 不会重新调整对象的更改,因此您必须在删除后调用 changedetection:https ://angular.io/api/core/ChangeDetectorRef
推荐阅读
- netty - 在 channelFuture 上调用同步不会阻塞线程
- javascript - 仅使用 jquery 或 javascript 更改图像
- azure - Azure 文件共享所有者/组权限在 VM 重新启动时恢复
- javascript - ESLint 缩进和操作符换行
- amazon-web-services - 如何通过 SAM cli 强制部署到 lambda
- python - 腌制抽象基类的动态定义扩展时出错
- python - 如何循环引导网格
- postgresql - 如何在 postgresql 中构建复杂的查询
- processing.js - sqrt(-1) 坏了。发生了什么?
- c - 读取写入内存空间