gpt4 book ai didi

javascript - 单击后将选中的项目移至同一页面的其他选项卡

转载 作者:行者123 更新时间:2023-12-03 03:50:04 25 4
gpt4 key购买 nike

我有一个消息列表。当一条消息被检查并保存时,该消息应该被移动到另一个选项卡 - 我们称之为“已保存”。我有这个功能;但是,每次保存后,最后一条消息都会覆盖前一条消息。我需要在每次保存后以某种方式附加消息而不操作 DOM。我使用的是 Ionic 3。消息是已保存的消息。 rmessages 是用户收到的消息。

typescript

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>

最佳答案

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

save(){

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

}

关于javascript - 单击后将选中的项目移至同一页面的其他选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45204408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com