1

如标题所述。我的 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 对象推入其中。这甚至可能是不可能的。

这是数据的总构建:

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);
      }

4

1 回答 1

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>

于 2017-11-04T00:20:31.137 回答