如何设置Alert复选框值和标签以从服务器

时间:2016-12-08 09:37:30

标签: typescript ionic2

这是Ionic 2关于提示复选框的示例提醒

     doCheckbox() {
       let alert = this.alertCtrl.create();
       alert.setTitle('Which planets have you visited?');

      alert.addInput({
        type: 'checkbox',
        label: 'Alderaan',
        value: 'value1',
        checked: true
       });

      alert.addInput({
        type: 'checkbox',
        label: 'Bespin',
        value: 'value2'
       });

     alert.addInput({
        type: 'checkbox',
        label: 'Coruscant',
        value: 'value3'
      });


     alert.addButton('Cancel');
     alert.addButton({
       text: 'Okay',
       handler: data => {
          console.log('Checkbox data:', data);
          this.testCheckboxOpen = false;
          this.testCheckboxResult = data;
         }
       });
    alert.present().then(() => {
    this.testCheckboxOpen = true;
   });
  }
 }

我的值来自服务器....例如,课程

      this.schoolAppUsers.loadCourses().subscribe(courses =>{
          this.courses = courses;
        }

....如何循环遍历课程并相应地将它们分配给值 有人可以解释一下这个例子的最后一部分:

     this.testCheckboxOpen = false;
     this.testCheckboxResult = data;

    alert.present().then(() => {
        this.testCheckboxOpen = true;
      });

......有人可以提供帮助,而不是

user.ts:

  export interface User {
UserID: number;
name: string;
username: string;
password: string;
userIDNumber: string;
role: number;
Course: string;
CourseName: string;
CourseID: number;
Venue: string;
message: string;
  }

service.ts

 loadCourses(): Observable<User>{
return this.http.get(`${this.userApiUrl}/getCourses.php`)
  .map(res => <User>res.json());
  }

1 个答案:

答案 0 :(得分:0)

要循环播放,您可以调用例如

schoolAppUser.loadCourses().subscribe(response =>{

    // loop through the list, assigning each item as 'course'
    for (let course of courses) {
       alert.addInput({
            type: 'checkbox',
            label: course.name,
            value: course.id
       });
    }
});