我有一个数组中的项目列表说,
Design
Analysis
Testing
Development
谁的索引,
0,1,2,3
在这里,我使用 angular dragula 用于拖放列表元素。使用dragula,我正在改变数组的位置说,
Analysis
Design
Development
Testing
顺序正在改变,但索引位置仍然相同,
1,0,3,2
这里的索引位置不是按顺序排列的,尽管它看起来像旧的索引值,但它看起来像旧的索引值。而无论数组内部发生什么变化,我都需要具有相同的索引位置,这意味着0,1,2,... so on
即使顺序发生变化,索引位置也应该从开始。
我用过的 Html 组件,
<div class="card-content">
<div dropDirective (dropEvent)="addDropItem($event)" class="droppable" [dropHighlight]="'highlight'">
<div [dragula]="'second-bag'">
<app-generic-drop-box *ngFor="let item of itemsDropped; index as i" (editBtn)='editBtn($event)' (deleteBtn)='deleteBtn($event)' [genericBox]='item' class="arrow_box dropItem temp" (click)='indexOfItem(i)'> </app-generic-drop-box>
</div>
</div>
</div>
在 ts 文件中,
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { ScenarioMapService } from '../scenario-map.service';
import { DynamicFormModel } from '../dynamic-form-config/dynamic-form-model';
import { Textbox } from '../dynamic-form-config/textbox';
import { CONFIG } from '../../app.config';
@Component({
selector: 'app-drop-area',
templateUrl: './drop-area.component.html',
styleUrls: ['./drop-area.component.scss']
})
export class DropAreaComponent implements OnInit, OnDestroy {
indexOfItem(i) {
console.log(i);
}
}
这里console.log(i)
显示了索引位置,如果用户单击列表,如果我更改数组的位置,我需要在更改后获取有序索引,如0,1,2,3...
..请帮助我实现结果。