Javascript 无法显示FirebaseDatabase中的数据
我试图在ng multiselect下拉列表中显示项目数组。当我硬编码数组中的值时,它们会显示出来,但是当我尝试从数据库中的项动态创建数组时,它们不会显示出来,即使它们准确地记录在数组中 save.component.tsJavascript 无法显示FirebaseDatabase中的数据,javascript,angular,firebase,asynchronous,async-await,Javascript,Angular,Firebase,Asynchronous,Async Await,我试图在ng multiselect下拉列表中显示项目数组。当我硬编码数组中的值时,它们会显示出来,但是当我尝试从数据库中的项动态创建数组时,它们不会显示出来,即使它们准确地记录在数组中 save.component.ts ... populateDropdown(callback) { let ham = this.students.snapshotChanges().map(changes => { return changes.map(c => ({k
...
populateDropdown(callback) {
let ham = this.students.snapshotChanges().map(changes => {
return changes.map(c => ({key: c.payload.key,...c.payload.val()}));
});
callback(ham);
}
ngOnInit() {
//stuff
this.fs.initFirebaseApp(environment.userFirebase, 'users');
this.students = this.fs.getList('/students');
let aCall = (data) => {
let count = 1;
data.forEach(student => {
student.forEach(element => {
this.dropdownList.push({
item_id: count++,
item_text: element.first + " " + element.last
});
});
});
}
this.populateDropdown(aCall);
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
selectAllText: 'Select All',
unSelectAllText: 'Unselect All',
itemsShowLimit: 3,
allowSearchFilter: true
};
console.log(this.dropdownList);
this.dropdownList1 = this.dropdownList.slice();
console.log(this.dropdownList1);
}
...
save.component.html
<ng-multiselect-dropdown
[placeholder]="'Select Students'"
[data]="dropdownList"
[(ngModel)]="selectedItems"
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
>
</ng-multiselect-dropdown>
检查我发布的示例希望它能帮助您并给我加一检查我发布的示例希望它能帮助您并给我加一
...
public initFirebaseApp(config: FirebaseAppConfig, firebaseAppName: string) {
this._db = new AngularFireDatabase(_firebaseAppFactory(config, firebaseAppName));
}
/** Function to get firebase DB list */
public getList(path: string): AngularFireList<{}> {
return this._db.list(path);
}
/** Function to get firebase DB object */
public getObject(path: string): AngularFireObject<{}> {
return this._db.object(path);
}
[{ item_id: 1, item_text: "Test Name" }
{ item_id: 2, item_text: "Alice Bob" }
{ item_id: 3, item_text: "Foo Name" }
{ item_id: 4, item_text: "Test Test" }]
```