我有所謂的後一個目的:AngularFire2 - 推並從對象陣列刪除
constructor(
public repliers: string[''],
public key: string = null
) {}
這裏是一個推手後的服務方法:
submitPost(post: Post) {
this.af.database.list('posts').push(post);
}
下面是其中所預訂的方法帖子表:
subscribeAllPosts(): Observable<Post[]> {
return this.af.database.list('posts')
.map(Post.fromJsonList);
}
在post類中,這裏是從json轉換它的靜態方法:
static fromJsonList(array:any): Post[] {
return array.map(Post.fromJson);
}
static fromJson({repliers, $key }:any): Post {
return new Post(repliers, $key);
}
當我提出它的工作原理後和火力點後的樣子:
posts
-> unique key
-> repliers
-> 0: ''
當我依次通過我的職位,我提交一個後看到陣列與一個默認爲空的屬性鍵。
我想解決的問題是如何更新posts表中的帖子,以便能夠將額外的鍵推送到repliers數組並從數組中刪除。
一個問題是如何更新此列表而不替換整個事物,因爲其他用戶也可能正在添加/刪除它。謝謝