首页 > 解决方案 > 继续两个单独数组的索引顺序

问题描述

我有一个具有“X”数组的对象(请注意,这些可以更大或更小):

note: PONotes
allNotes: Array(6)
0: PONote {_text: "Contratación", _date: "", _author: ""}
1: PONote {_text: "Acordamos día de instalación con el técnico de Jazztel", _date: "", _author: ""}
2: PONote {_text: "Instalación y entrega de equipos. Ya puedes Navegar. Iniciamos la portabilidad de tu linea fija", _date: "", _author: ""}
3: PONote {_text: "Linea activada el día de tu portabilidad", _date: "", _author: ""}
4: PONote {_text: "Iniciamos la portabilidad de tu línea móvil", _date: "", _author: ""}
5: PONote {_text: "Introduce Nueva Sim el día de tu portabilidad", _date: "", _author: ""}
length: 6
__proto__: Array(0)
__proto__: Object

我已使用以下函数将此对象分成两个数组:

private getOrderNotes(orderNotes: ProductOrderModel) {
    this.activationDeadlinesGraphicViewModel.phoneNumberOrderNotes = orderNotes.note.getAllNotes()
    .slice(0, this.activationDeadlinesGraphicViewModel.state);

    this.activationDeadlinesGraphicViewModel.cellphoneNumberOrderNotes = orderNotes.note.getAllNotes()
    .slice(-this.activationDeadlinesGraphicViewModel.type);
  }

切片中的状态类型为我提供了每个数组所需的项目数。

这是this.activationDeadlinesGraphicViewModel.phoneNumberOrderNotes的数组

(4) [PONote, PONote, PONote, PONote]
0: PONote {_text: "Contratación", _date: "", _author: ""}
1: PONote {_text: "Acordamos día de instalación con el técnico de Jazztel", _date: "", _author: ""}
2: PONote {_text: "Instalación y entrega de equipos. Ya puedes Navegar. Iniciamos la portabilidad de tu linea fija", _date: "", _author: ""}
3: PONote {_text: "Linea activada el día de tu portabilidad", _date: "", _author: ""}
length: 4
__proto__: Array(0)

这是this.activationDeadlinesGraphicViewModel.cellphoneNumberOrderNotes的数组

(2) [PONote, PONote]
0: PONote {_text: "Iniciamos la portabilidad de tu línea móvil", _date: "", _author: ""}
1: PONote {_text: "Introduce Nueva Sim el día de tu portabilidad", _date: "", _author: ""}
length: 2
__proto__: Array(0)

我必须在有序列表中打印它,第一个数组编号从 1 到 4,第二个数组编号从 5 到 6。

因为它们在单独的数组中,所以我打印索引并添加 +1,所以它不会从 0 开始。对于第一个数组,它就像一个魅力,但由于第二个数组再次从 0 开始,我不知道如何将索引更改为下一个我需要基于最后一个数组的数字。

<ng-container *ngFor="let phoneNumberOrderNotes of activationDeadlinesGraphicViewModel.phoneNumberOrderNotes; let i = index;">
    <ion-row>
        <ion-item>
            <ion-col col-1>
                <span [class.numberCircleFilled]="activationDeadlinesGraphicViewModel.baseType > i"
                    [class.numberCircleUnfilled]="activationDeadlinesGraphicViewModel.baseType <= i">
                    {{ i+1 }}
                </span>
            </ion-col>
            <ion-col col-11>
                <span>{{ phoneNumberOrderNotes.text }}</span>
            </ion-col>
        </ion-item>
    </ion-row>
</ng-container> 

<ng-container *ngFor="let cellphoneNumberOrderNotes of activationDeadlinesGraphicViewModel.cellphoneNumberOrderNotes; let i = index;">
    <ion-row>
        <ion-item>
            <ion-col col-1>
                <span [class.numberCircleFilled]="activationDeadlinesGraphicViewModel.baseType < i"
                    [class.numberCircleUnfilled]="activationDeadlinesGraphicViewModel.baseType >= i">
                    {{ i+1 }}
                </span>
            </ion-col>
            <ion-col col-11>
                <span>{{ cellphoneNumberOrderNotes.text }}</span>
            </ion-col>
        </ion-item>
    </ion-row>
</ng-container>

在此处输入图像描述

最后两个应该是 5 和 6。

标签: htmlarraysobjectionic3angular5

解决方案


添加phoneNumberOrderNotes.length到您的最后一个i以获得连续编号。


推荐阅读