如何从嵌套的ngFor循环中的离子选择中获取值?

时间:2017-11-03 23:40:52

标签: angular ionic-framework ionic3 ngfor ngmodel

正如标题所述。我的html中有一个嵌套的ngFor循环。我在ngFor语句中使用了其中一个ion-select循环。这是我的代码:

<ion-item *ngFor="let item of pageOptions" >
      <ion-label>{{item.attender.FIRST_NAME}} {{item.attender.LAST_NAME}}</ion-label>
      <ion-select multiple="true">
        <ion-option value="item" *ngFor="let item of item.options">{{item.ATTENDER_NAME}} ${{item.PARTICIPANT_PRICE}}</ion-option>
      </ion-select>
</ion-item>

我想弄清楚如何使用*ngFor="let item of item.options"[(ngModel)]中获取价值。

任何人都可以帮我解决这个难题吗?

先谢谢

我被问到了我的数据。我有一个数组,我将这个对象推入:let item = { attender: member, options: [{}] };选项部分获取一个JSON对象推入其中。这可能是不可能的。

以下是数据的总体构建:

&#13;
&#13;
this.attenders = this.clickedItem.attenders;
      this.attenderOptions = this.clickedItem.activityDefinition.ATTENDERS; //this might not be ATTENDERS
      this.positionOptions = this.clickedItem.activityDefinition.POSITIONS;
      this.guests = this.clickedItem.guests;
      for (var i = 0; i < this.attenders.length; i++) {
        let item = {
          attender: this.attenders[i],
          options: []
        };
        for (var j = 0; j < this.attenderOptions.length; j++) {
          let minAge = this.attenderOptions[j].MIN_PARTICIPANT_AGE;
          let maxAge = this.attenderOptions[j].MAX_PARTICIPANT_AGE;
          let minGrade = this.attenderOptions[j].MIN_PARTICIPANT_GRADE;
          let maxGrade = this.attenderOptions[j].MAX_PARTICIPANT_GRADE;
          let availablePositions = this.attenderOptions[j].AVAILABLE_POSITIONS;
          var birthdate = this.convertBirth(this.attenders[i].BIRTH_DAY, this.attenders[i].BIRTH_MONTH, this.attenders[i].BIRTH_YEAR)
          var gradeString = this.attenders[i].GRADE;
          var grade = this.convertGrade(gradeString);
          if (availablePositions > 0) {
            if ((this.compareMinDates(birthdate, minAge) && this.compareMaxDates(birthdate, maxAge)) || (this.compareMinGrades(grade, minGrade) && this.compareMaxGrades(grade, maxGrade))) {
              //within age constraints
              item.options.push(this.attenderOptions[j]);
            } else if (minAge == "" && maxAge == "" && minGrade == "" && maxGrade == "") {
              item.options.push(this.attenderOptions[j]);
            }
          }
        }
        for (var j = 0; j < this.positionOptions.length; j++) {
          if (this.positionOptions[i] != undefined) {
            let minAge = this.positionOptions[j].MIN_PARTICIPANT_AGE;
            let maxAge = this.positionOptions[j].MAX_PARTICIPANT_AGE;
            let minGrade = this.positionOptions[j].MIN_PARTICIPANT_GRADE;
            let maxGrade = this.positionOptions[j].MAX_PARTICIPANT_GRADE;
            let availablePositions = this.positionOptions[j].POSITIONS_REMAINING;
            var birthdate = this.convertBirth(this.attenders[i].BIRTH_DAY, this.attenders[i].BIRTH_MONTH, this.attenders[i].BIRTH_YEAR)
            var gradeString = this.attenders[i].GRADE;
            var grade = this.convertGrade(gradeString);
            if (availablePositions >= 0) {
              if ((this.compareMinDates(birthdate, minAge) && this.compareMaxDates(birthdate, maxAge)) || (this.compareMinGrades(grade, minGrade) && this.compareMaxGrades(grade, maxGrade))) {
                //within age constraints
                this.positionOptions[i].ATTENDER_NAME = this.positionOptions[i].POSITION_NAME;
                this.positionOptions[i].PARTICIPANT_PRICE = 0;
                item.options.push(this.positionOptions[j]);
              } else if (minAge == "" && maxAge == "" && minGrade == "" && maxGrade == "") {
                this.positionOptions[i].ATTENDER_NAME = this.positionOptions[i].POSITION_NAME;
                this.positionOptions[i].PARTICIPANT_PRICE = 0;
                item.options.push(this.positionOptions[j]);
              }
            }
          }
        }
        this.pageOptions.push(item);
      }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我认为这应该有用

 <ion-item *ngFor="let item of pageOptions" >
  <ion-label>{{item.attender.FIRST_NAME}} {{item.attender.LAST_NAME}}</ion-label>
  <ion-select [(ngModel)]="select"  multiple="true">
    <ion-option value="item" *ngFor="let item of item.options">{{item.ATTENDER_NAME}} ${{item.PARTICIPANT_PRICE}}</ion-option>
  </ion-select>