3

http://ionicframework.com/docs/v2/components/#select

我正在尝试显示选择选项并捕获选择。我已经尝试过方法、onChanges 甚至在点击时内联,但没有任何效果。

<ion-list>
    <ion-item>
        <ion-label>List </ion-label>
        <ion-select [(ngModel)]="selected" multiple="true" cancelText="Cancel" okText="Okay!">
            <ion-option *ngFor="#row of list;" value="{{row.id}}" (click)="checkSelected(row.id)" checked="{{ gq.isSelected(row.id) }}">{{ row.english_name }}</ion-option>
        </ion-select>
    </ion-item>
</ion-list>

设置页面类

export class SettingPage implements OnChanges{

    selected;
    list = [];

    constructor(private nav:NavController, public gq: gq)
    {
        this.gq
            .list()
            .subscribe(data => this.list.push(data));
    }
    stpSelect() {
        console.log('STP selected');
        console.log(this.selected);

    }
    ngOnChanges(changes) {
        console.log(changes);
    }

    checkSelected (data)
    {
        console.log('test');
        console.log(data);
    }
}

当事情发生变化时,我只想从函数中捕获选定的模型值。

4

1 回答 1

2

由于 ion-select 组件利用ngModel,您可以尝试监听ngModelChange事件:

<ion-select [(ngModel)]="selected" multiple="true" cancelText="Cancel" okText="Okay!" (ngModelChange)="doSomething()">
  (...)
</ion-select> 
于 2016-02-21T08:02:45.037 回答