javascript - Javascript推送功能
问题描述
我想创建简单的社交媒体应用程序。我现在正在与组一起工作。但我不能只过滤某些用户是成员的组。代码如下
import { Component, OnInit, OnChanges } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/database';
import { GroupsService } from '../groups.service';
@Component({
selector: 'app-groups',
templateUrl: './groups.component.html',
styleUrls: ['./groups.component.scss']
})
export class GroupsComponent implements OnInit {
uid = localStorage.getItem('uid')
groups: Array<any>;
mygroups: Array<any>;
sgroups;
constructor(private db: AngularFireDatabase, private _groups: GroupsService) {
}
ngOnInit() {
this._groups.getGroups().subscribe((data) => {
this.groups = data;
})
this.loadGroups()
}
search(e) {
this.sgroups = this.groups.find(gr => gr.name.toLowerCase().indexOf(e.target.value.toLowerCase()) > -1)
}
loadGroups() {
this.groups.map(gr => {
this._groups.getGroupMembers(gr.id).subscribe((data: any) => {
data.map(mem => {
if(mem.uid == this.uid) {
this.mygroups.push(gr); //here is the problem
}
})
})
})
}
scrollnav() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
}
欢迎任何帮助。非常感谢!
解决方案
问题在于初始化。初始化 mygroups 像
mygroups: any[] = [];
代替
mygroups: Array<any>;
推荐阅读
- reactjs - 当 row.revision > this.state.selectedEstimate.revision 时,我想尝试行颜色
- python - 如何在odoo 10中打开一个url并从那里返回数据?
- python - Python/JSON:一个接一个的错误
- javascript - Javascript 在 chrome 扩展中打开多个标签
- linux - 如何在安装 MongoDB 时解决我的 Ubuntu 18.04 LTS 上的以下“密钥服务器接收失败”问题?
- javascript - 如何在 .pptx 文件中嵌入字体
- javascript - 如何测试用多个高阶组件包装的组件?
- c# - WPF - 绑定获取属性
- elasticsearch - 使用 java API 进行 Elasticsearch 排序
- payment-gateway - PayUmoney 支付每次都失败