我正在尝试在 firebase 中插入数据。但问题是它显示嵌套数据错误。如何将嵌套数组转换为简单数组,以便可以放入 firebase?
这是我的 .ts 代码
create() {
this.checked.push(this.user.userId);
if(this.Name == ""){
this.toast.show('Please give a group name');
}
else{
// the user details are updated in firebase user list
this.groupDetails = {
groupname: this.Name,
description: this.description || '',
members: this.checked,
messages: [],
createdId: this.user.userId,
createrName: this.user.username
}
console.log(this.groupDetails);
// details are submitted to creatGroup function from groupProvider
this.messageService.createGroup(this.groupDetails).then(resp => {
console.log(resp);
this.toast.show("Group Created");
this.router.navigate(["/home"]);
});
}
}
addCheckbox(event, checkbox : String, userName : String) {
console.log(event);
if ( event.detail.checked ) {
this.checked.push([{member_id:checkbox, member_name:userName}]);
console.log(this.checked);
} else {
let index = this.removeCheckedFromArray(checkbox);
this.checked.splice(index,1);
}
}
//Removes checkbox from array when you uncheck it
removeCheckedFromArray(checkbox : String) {
return this.checked.findIndex((category)=>{
return category === checkbox;
console.log(this.checked);
})
}
我的html代码是这样的
<ion-content >
<ion-item>
<ion-input type="text" [(ngModel)]="Name" name="Name" placeholder="Group Name" class="custom-input"></ion-input>
</ion-item>
<div class="spacer" style="height: 5px;"></div>
<ion-item>
<ion-textarea type="text" row="8" [(ngModel)]="description" name="description" placeholder="Group Description" class="custom-input"></ion-textarea>
</ion-item>
<ion-list>
<ion-item *ngFor="let usr of usersList" >
<ion-label>{{usr.username}}</ion-label>
<ion-checkbox slot="start" (ionChange)="addCheckbox($event,usr.userId, usr.username)"></ion-checkbox>
</ion-item>
</ion-list>
</ion-content>
<ion-footer>
<ion-button expand="block" class="g-btn" (click)="create()">Create Group</ion-button>
</ion-footer>
问题是在 memebrs 数组中引起的。我附上了控制台的屏幕截图,成员数组的外观我认为需要在简单数组中更改此数组吗?
