我有几个级别的嵌套列表,在onDropSuccess上我想传递给函数onDropSuccess所有父索引,包括我正在删除项目的那个。所以我想通过listitem,rowitem和cellitem。如何做到这一点,以便我可以在所有嵌套子项中重用该函数?
<div *
ngFor="let tableitem of table; let listitem = index"
(onDropSuccess)="onDropSuccess($event, passAllIndexAboveIncludingThisOne )"
>
<div *ngFor="let rowitem of tableitem.rowitem; let rowitem = index"
(onDropSuccess)="onDropSuccess($event, passAllIndexAboveIncludingThisOne )"
>
<div *ngFor="let cell of rowitem.cell; let cellitem = index"
(onDropSuccess)="onDropSuccess($event, passAllIndexAboveIncludingThisOne )"
>
Something data here
</div></div></div>
答案 0 :(得分:1)
这样的事情应该有效。我刚刚重命名了所有索引,let
之后的第一个变量和影响索引的变量之间存在一些重复。然后我想你可以自己看到我使用标准数组,将变量传递给函数。
<div *ngFor="let tableitem of table; let indexItem = index" (onDropSuccess)="onDropSuccess($event, indexItem)">
<div *ngFor="let rowitem of tableitem.rowitem; let indexRow = index" (onDropSuccess)="onDropSuccess($event, [indexItem, indexRow])">
<div *ngFor="let cell of rowitem.cell; let indexCell = index" (onDropSuccess)="onDropSuccess($event, [indexItem, indexRow, indexCell] )" >
Something data here
</div>
</div>
</div>
您可以像这样使用onDropSuccess
:
onDropSuccess(event, datas) {
console.log(event, datas);
}