2017-09-08 62 views
1

我從我的數據庫中填充複選框,並且我希望用戶能夠完成複選框表單並將其提交回數據庫。我無法弄清楚如何獲取動態填充的複選框的值。代碼如下。Ionic 2獲取動態複選框的值

export class ListPage { 
    checklists: any; 
    checkedData: any; 
    checklist:any; 
    a:any; 

    constructor(public navCtrl: NavController, public navParams: 
    NavParams, public http: Http, public data: checklistData) { 

     this.data.checklistdata().then(result => { 
      this.checklists = result; 
      console.log(this.checklists) 
     }); 

     for(this.a=0; this.a>0; this.a++){ 
      console.log(this.checklist.checked) 
     } 
    } 
} 

<div *ngFor="let checklist of checklists; let i=index "> 
    <ion-item> 
    <ion-label>{{checklist.name}}</ion-label> 
    <ion-checkbox [(ngModel)]="checklist.checked"></ion-checkbox> 
    </ion-item> 
</div> 

<b>selectedItems</b>: <div *ngFor="let checklist of checklists">{{checklist.checked}}</div> 

回答

0

I`ve發現基於本地JavaScript一個簡單的解決方案:

let checkboxes = document.getElementsByClassName("checkbox"); 
for (var i=0 ; i< checkboxes.length ; i++) { 
    console.log(checkboxes[i].getAttribute("checked")) 

}