indexOf在ionic3中搜索数组中的对象时不起作用?

时间:2018-05-07 04:51:48

标签: ionic3

我必须得到所选对象的索引但我每次都返回-1告诉我我的代码中有什么错误我会更新html和ts代码吗?



addOrRemoveSubcategory(event:any, subCategroyObject: any) {
    //For firestore - Here we will hold the subcateoryObject and push into array 
    this.checkedCategoryObject = {
      "id"                 : subCategroyObject.keyId,
      "subCategoryName"    : subCategroyObject.subCategoryName
    }

    if(event.checked) {
      this.selectedSubCategoryKeyId = subCategroyObject.keyId;
      //Push only if not eixst in the array
      if(this.selectedSubCategoryArray.indexOf(this.checkedCategoryObject.id) == -1){
        this.selectedSubCategoryArray.push(this.checkedCategoryObject);
      }
    } else {
      this.selectedSubCategoryKeyId = subCategroyObject.keyId;
      var index         = this.selectedSubCategoryArray.indexOf(this.checkedCategoryObject);
      this.selectedSubCategoryArray.splice(index, 1);
    }
  }

<ion-item-sliding>
  <ion-item *ngFor="let subCategoryObj of adminSubCategrotDto">
    <ion-checkbox dark (ionChange)="addOrRemoveSubcategory($event, subCategoryObj)"
       item-left>
    </ion-checkbox>
    <ion-label>{{subCategoryObj.subCategoryName}}</ion-label>
    <ion-avatar item-start>
      <img src="{{subCategoryObj.defaultImageURL}}">
    </ion-avatar>
  </ion-item>
</ion-item-sliding>
&#13;
&#13;
&#13;

enter image description here

0 个答案:

没有答案