鍍金池/ 問答/HTML5  網絡安全/ ionic3 頁面數據更換 通過‘radio’

ionic3 頁面數據更換 通過‘radio’

當選擇一月的時候,想讓頁面更換數據為一月志愿者資料,但是點擊過后,瀏覽器log可以顯示一月數據,只是頁面數據不進行更換。
圖片描述

這個是log出來的資料
圖片描述

html page

<ion-header>
    <ion-toolbar color="danger">
      <ion-buttons>
        <button ion-button navPop icon-only>
          <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon>
        </button>
      </ion-buttons>
      <ion-buttons style="background: transparent;" end> 
        <button style="background: transparent;" (click)="doRadio()">月份選擇</button>
      </ion-buttons>
        <ion-title text-wrap>志愿者評選</ion-title>
    </ion-toolbar>
</ion-header>

<ion-content>

  <ion-grid>
    <ion-row>
      <ion-col>
        <ion-card (click)="goToVolunteerVoteDetail(volunteer)" style="width:26%" class="pin" *ngFor="let volunteers of volunteer">
          <img src="{{volunteers.Preview_image1}}" height="100">
          <div *ngIf="volunteers.title" class="volunteer-title">
            <small>{{volunteers.title}}</small>
          </div>
          <div class="volunteer-title">{{volunteers.like_number}}分</div> <!-- 志愿者評選頭像像素:505x505px -->
        </ion-card>
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

ts page

import { Component } from '@angular/core';
import { NavController, NavParams, ToastController, AlertController, ModalController } from 'ionic-angular';
import { NewsDataProvider } from '../../providers/news-data/news-data';
import { VolunteerVoteDetailPage } from '../volunteer-vote-detail/volunteer-vote-detail';
// import { VolunteerVotePopPage } from '../volunteer-vote-pop/volunteer-vote-pop';


@Component({
  selector: 'page-volunteer-vote',
  templateUrl: 'volunteer-vote.html',
})
export class VolunteerVotePage {
  volunteer:any;
  volunteer1:any;
  //volunteer2:any;
  // testRadioOpen = false;
  // testRadioResult: any;

  constructor(
    public navCtrl: NavController, public navParams: NavParams,
    public newsData:NewsDataProvider,public toastCtrl: ToastController,
    public alertCtrl: AlertController,public modalCtrl: ModalController
  ){
    this.getVolunteerVote();
    this.getVolunteerVote1();
    //this.getVolunteerVote2();
  }

  getVolunteerVote(): Promise<any> {
    return this.newsData.getVolunteerVote().then(data => {
      this.volunteer = data;
    });
  }
  getVolunteerVote1(): Promise<any> {
    return this.newsData.getVolunteerVote1().then(data => {
      this.volunteer1 = data;
    });
  }
  // getVolunteerVote2(): Promise<any> {
  //   return this.newsData.getVolunteerVote2().then(data => {
  //     this.volunteer2 = data;
  //   });
  // }

  goToVolunteerVoteDetail(volunteerItem:any) {
    this.navCtrl.push(VolunteerVoteDetailPage,{
      volunteer:volunteerItem
    });
  }

  doRadio() {
    const alert = this.alertCtrl.create();
    alert.setTitle('請選擇月份');

    alert.addInput({
      type: 'radio',
      label: '1月',
      value: this.volunteer1,
      checked: true
    });

    // alert.addInput({
    //   type: 'radio',
    //   label: '2月',
    //   value: this.volunteer2
    // });

    alert.addButton({
      text: '確認',
      handler: (data: any) => {
        console.log('Radio data:', data);
        // this.testRadioOpen = false;
        // this.testRadioResult = data;
      }
    });
    alert.addButton('取消');

    alert.present();
  }


}

provide page

getVolunteerVote() {
    return new Promise(resolve => {
      this.http.get('http://servertrj.com/api/news/index/16?api_key=123').map(res => res.json().data).subscribe(data => {
          this.data = data;
          resolve(this.data);
        });
    });
  }
  getVolunteerVote1() {
    return new Promise(resolve => {
      this.http.get('http://servertrj.com/api/news/index/22?api_key=123').map(res => res.json().data).subscribe(data => {
          this.data = data;
          resolve(this.data);
        });
    });
  }

回答
編輯回答
情皺

你循環(huán)的是volunteer可是你獲取1月數據的時候沒有給它重新賦值啊。。。

2018年5月3日 16:29