Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 索引正确时未定义离子4子数组_Javascript_Html_Typescript_Ionic Framework_Ionic4 - Fatal编程技术网

Javascript 索引正确时未定义离子4子数组

Javascript 索引正确时未定义离子4子数组,javascript,html,typescript,ionic-framework,ionic4,Javascript,Html,Typescript,Ionic Framework,Ionic4,我尝试使用console.log来查看该值,但是noticest2[index]值未定义。当我打印noticeSet时,它将显示数组中的所有数据。我尝试在console.log中打印索引,它会显示与数组匹配的索引 我尝试在主菜单的子菜单中创建一个子菜单,它是noticeSet,主菜单工作正常。我尝试了类似的方法,但不起作用。我现在需要解决的就是显示noticest2[index]值。谢谢 toggleItem(index, item) { //this.noticeSet2[index

我尝试使用console.log来查看该值,但是noticest2[index]值未定义。当我打印noticeSet时,它将显示数组中的所有数据。我尝试在console.log中打印索引,它会显示与数组匹配的索引

我尝试在主菜单的子菜单中创建一个子菜单,它是noticeSet,主菜单工作正常。我尝试了类似的方法,但不起作用。我现在需要解决的就是显示noticest2[index]值。谢谢

toggleItem(index, item) {

    //this.noticeSet2[index].open = !this.noticeSet2[index].open;

    console.log("here");
    console.log(this.noticeSet2[0]);
    console.log(this.noticeSet2[index]);
    console.log(index);

    let obj = {resident_id: this.resident_id,id: item.id}

    this.authService.postData(obj, "getSubCategoryList").then((result) =>{
      this.responseData = result;
        if(this.responseData.feedData){
          //this.noticeSet2[item.id] = this.responseData.feedData;
          this.noticeSet3[this.noticeSet2[item.id]] = this.responseData.feedData;
          this.isDataAvailable = true;
        //console.log(this.noticeSet);
        }
      }, (err) => {
      });
  }

<ion-list *ngFor="let item of noticeSet; let i = index;" lines="none"  class="accordion-list" detail="false"
    no-padding >

    <button ion-item tappble style="font-weight:bold;color:#424242;" (click)="getSubCategoryList(i,item)" [ngClass]="{'section-active':item.open,'section':!item.open}">
      <ion-icon item-right slot="end" name="arrow-forward" *ngIf="!item.open"
        style="font-size: 16px;font-weight: bold;"></ion-icon>
      <ion-icon item-right slot="end" name="arrow-down" *ngIf="item.open"
        style="font-size: 16px;font-weight: bold;color:rgb(74, 137, 220)"></ion-icon>
      {{ item.title }}
    </button>


    <div *ngIf="noticeSet2[item.id] && item.open">
      <ion-list *ngFor="let item of noticeSet2[item.id]; let j = index;" lines="none" class="child-list">
        <button ion-item  (click)="toggleItem(j,item)" *ngIf="item.title"
          [ngClass]="{'child-active':item.open, 'child':!item.open}">
          <ion-icon item-left slot="start" name="add" *ngIf="!item.open" style="font-size: 12px;font-weight: bold;">
          </ion-icon>
          <ion-icon item-left slot="start" name="close" *ngIf="item.open" style="font-size: 12px;font-weight: bold;">
          </ion-icon>
          <ion-label>
            {{ item.title }}
          </ion-label>
        </button>

        <div *ngIf="noticeSet3[this.noticeSet2[item.id]] && item.open">
         <ion-list  *ngFor="let item of noticeSet3[this.noticeSet2[item.id]]" class="child-list-list" lines="none">
          <ion-item class="child-item" *ngIf="item.title">
            <button ion-item >
              {{item.title}}
            </button>
          </ion-item>
        </ion-list>
      </div>

      </ion-list>
    </div>
  </ion-list>
toggleItem(索引,项){
//this.noticest2[index].open=!this.noticest2[index].open;
console.log(“此处”);
console.log(this.notices2[0]);
console.log(this.noticest2[index]);
控制台日志(索引);
设obj={resident\u id:this.resident\u id,id:item.id}
this.authService.postData(obj,“getSubcategory列表”)。然后((结果)=>{
this.responseData=结果;
if(此响应数据反馈数据){
//this.noticeSet2[item.id]=this.responseData.feedData;
this.noticest3[this.noticest2[item.id]]=this.responseData.feedData;
this.isDataAvailable=true;
//console.log(this.noticeSet);
}
},(错误)=>{
});
}

{{item.title}
{{item.title}
{{item.title}

这是因为您在承诺中使用了价值。 有两种方法可以继续:

第一个是使用

。然后(函数()=>{[…]}

而不是

.然后((结果)=>{[…]}

它会起作用的

第二种方法是使用不在{}内的特殊变量

    var that = this;
// ...
.then(function() { that.variable })

希望能有所帮助。

谢谢你的回复,我已经试过了,但是没有用=3=