Javascript 删除嵌套数组中对象的行角度为2/4
我有一个模型,在对象数组中包含数组:Javascript 删除嵌套数组中对象的行角度为2/4,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,我有一个模型,在对象数组中包含数组: <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
<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
有效吗?我猜你错过了(单击)=“…”
绑定,很抱歉,这是我更正的类型。代码运行正常,只是没有删除拼接中的行。感谢您在拼接后添加console.log(this.shops.locations[this.indexi].locationssub,length)?我添加了,但没有添加任何内容。没有错误。此外,条目不会被删除。问题是嵌套数组和索引看起来很像你确定吗?为什么angular无法识别?代码有效,但条目不会被删除。没有错误。你能提供一个产生相同错误的例子吗?你可以用
select(n, i){
this.indexi=i;
this.locationssub=n;
this.popup.show();
}
delete(subloc, j){
this.shops.locations[this.indexi].locationssub.splice(j,1);
}