【问题标题】:how to clear all list in ionic2如何清除ionic2中的所有列表
【发布时间】:2017-03-13 10:00:54
【问题描述】:

我在 ionic 2 项目中工作,创建了滑动以删除每个工作正常的项目,还需要单击按钮删除所有项目如何从角度 2 中的列表中删除所有项目?

<button ion-button clear>Clear All</button>    
<ion-item-sliding *ngFor="let note of notes">
          <ion-item>
              {{note.title}}
          </ion-item>
          <ion-item-options>
              <button (click)="deleteNote(note)" danger>
                  <ion-icon name="trash"></ion-icon>
              </button>
          </ion-item-options>
        </ion-item-sliding>

文件.ts

constructor( public viewCtrl: ViewController ) { 
    this.notes = [
      { title: 'This is notification swipe to delete' },
      { title: 'This is notification swipe to delete' }    
      ];
  }
deleteNote(note){

        let index = this.notes.indexOf(note);

        if(index > -1){
            this.notes.splice(index, 1);
        }
    }

【问题讨论】:

    标签: angular typescript ionic-framework ionic2 ionic3


    【解决方案1】:

    您可以像这样创建clear() 方法

    public clear(): void {
      this.notes = [];
    }
    

    从视图中调用它

    <button ion-button clear (click)="clear()">Clear All</button>  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      相关资源
      最近更新 更多