简体   繁体   English

从角度2的对象文字获取存储的索引

[英]Get stored index from object literal in angular 2

I have a stored object literal which returns 2 or more objects depending on the users actions. 我有一个存储的对象文字,它根据用户的操作返回2个或更多对象。 This is then filtered further depending on if they are complete or not, so there are generally 2 object arrays that are sent to the view. 然后根据它们是否完成进一步过滤,因此通常有2个对象数组发送到视图。

in the view i do a simple ngFor 在视图中,我做了一个简单的ngFor

 <ion-card *ngFor="let item of inProgressList">
    ...

Which is a segment of the complete list held in a variable programsList 这是完整列表的一部分,保存在变量programsList

In order to change an item from in progress to complete i need to update the object, which works fine, however i cannot correctly pass the index. 为了从改变一个项目in progress ,以complete我需要更新的对象,它工作得很好,但我不能正确地传递索引。

filledOutFormsData[this.index].complete = true;

As i cannot get the correct index based on the array that has been filtered. 因为我无法基于已过滤的数组获取正确的索引。

I cannot use 我不能使用

  <ion-card *ngFor="let item of inProgressList; let i = index">

Because that will return a index of the looped items which will be incorrect once one other object is equal to complete 因为这将返回循环项目的索引,一旦另一个对象等于complete ,该索引将是错误的

Basically i need to get the object key from the original object literal into the filtered array to use in the view so that i can pass the index. 基本上,我需要将原始对象文字的对象键放入过滤后的数组中,以便在视图中使用,以便可以传递索引。

因此,我通过添加一个自定义管道来对其进行工作,该管道用于过滤programsList而不是传递两个单独的列表,然后可以使用trackBy选项传递正确的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM