单击后,将选中的项目移动到同一页面中的其他选项卡

时间:2017-07-20 03:07:42

标签: javascript arrays typescript ionic-framework ionic2

我有一个消息列表。检查并保存邮件后,应将该邮件移至另一个选项卡 - 让我们将其保存。我有这个功能;但是,每次保存后,最后一条消息将覆盖前一条消息。我需要以某种方式在每次保存后附加消息而不操纵DOM。我正在使用Ionic 3.amessages是已保存的消息。 rmessages是用户收到的消息。

打字稿

import { Component } from '@angular/core';
import { NavController} from 'ionic-angular';

@Component({
  selector: 'page-messages',
  templateUrl: 'messages.html'
})
export class MessagesPage {
selectedAll: boolean = false;
messages: string = 'messages';
singleChecked: boolean = false;
rmessages: any[] = [
    { text: 'This is a test message.' , selected: false },
    { text: 'This is a second test message.', selected: false },
    { text: 'This is a third test message.', selected: false }
  ];
 amessages: any[] = []; 

  constructor(public navCtrl: NavController) { 
}


checkAll(){
  console.log(this.messages.length)
  if(this.selectedAll){
    this.selectedAll = true
  }
  else {
    this.selectedAll = false
  }
}

save(){

this.amessages = this.rmessages.filter(function(x) { return x.selected})

this.rmessages.filter(function (x){ 
      return x.selected;}).map(function(y){ 
        return y.text;});
  this.rmessages =  this.rmessages.filter(function (x) { return !x.selected;})

}

HTML

<ion-content class="checks">

    <div [ngSwitch]="messages">

    <ion-list active *ngSwitchCase="'received'">
      <ion-item>
        <ion-label>select all</ion-label>
        <ion-checkbox (click)="checkAll()" [(ngModel)]="selectedAll" ></ion-checkbox>
      </ion-item>

    <ion-item *ngFor="let rmessage of rmessages; index as i">
        <ion-label>{{rmessage.text}}</ion-label>
        <ion-checkbox [checked]="selectedAll" [(ngModel)]="rmessage.selected" ></ion-checkbox>
    </ion-item>
        <button ion-button full (click)="save()"  style="font-size:1.8rem">save</button>
    </ion-list>

  <ion-list radio-group *ngSwitchCase="'sent'">
    <ion-list-header>Saved Messages</ion-list-header>
        <ion-item *ngFor="let amessage of amessages; index as i" >
        <ion-label>{{amessage.text}}</ion-label>
        </ion-item>
  </ion-list>
</div>
</ion-content>

1 个答案:

答案 0 :(得分:1)

只需将save()函数更改为:

collect