我需要将两个对象列表合而为一。 第一个列表是我创建的电影。 第二个列表是分享我的电影。 我想加入这两个列表,以便它们按字母顺序混合和排序,因为现在它们是分开的。
(3) [{…}, {…}, {…}]
0: {compartir_con: "", descripcion: "", id: "", link_descarga: "", portada: "", …}
1: {compartir_con: "", descripcion: "", id: "", link_descarga: "", portada: "", …}
2: {compartir_con: "", descripcion: "", id: "", link_descarga: "", portada: "", …}
length: 3
__proto__: Array(0)
list-films.component.ts:68
[{…}]
0: {compartir_con: "", descripcion: "", id: "", link_descarga: "", portada: "", …}
length: 1
__proto__: Array(0)
在我电影的html中:
<div *ngFor="let film of (films | orderBy: ['+vista','+titulo'] ) | grdFilter: {titulo: searchText, descripcion: searchText};">
在共享电影的html中:
<div *ngFor="let film of (shared | orderBy: ['+vista','+titulo'] ) | grdFilter: {titulo: searchText, descripcion: searchText};">
这是我的data-api.service.ts
getAllYourFilms(id) {
this.filmsCollection = this.afs.collection('films', ref =>
ref.where('userUid', '==', id));
return this.films = this.filmsCollection.snapshotChanges()
.pipe(map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as FilmInterface;
data.id = action.payload.doc.id;
return data;
});
}));
}
getAllFilmsSharedWithYou(email) {
this.filmsCollection = this.afs.collection('films', ref =>
ref.where('compartir_con', '==', email));
return this.films = this.filmsCollection.snapshotChanges()
.pipe(map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as FilmInterface;
data.id = action.payload.doc.id;
return data;
});
}));
}
我的list-films.component.ts
getListFilms(iduser) {
this.dataApi.getAllYourFilms(iduser)
.subscribe(films => {
this.films = films;
console.log(films);
});
}
getListFilmsShared(email) {
this.dataApi.getAllFilmsSharedWithYou(email)
.subscribe(films => {
this.shared = films;
console.log(films);
});
}
我需要所有电影都放在同一阵列中。
[0]{…}
[1]{…}
[2]{…}
[3]{…}
但实际上是:
我的电影
[0]{…}
[1]{…}
[2]{…}
与我分享
[0]{…}
解决方案
我编辑此功能(list-films.component.ts):
getListFilmsShared(email) {
this.dataApi.getAllFilmsSharedWithYou(email)
.subscribe(films => {
this.films = this.films.concat(films);
});
}