Javascript Firebase更新嵌套数组中的对象

Javascript Firebase更新嵌套数组中的对象,javascript,angular,google-cloud-firestore,angularfire2,Javascript,Angular,Google Cloud Firestore,Angularfire2,在Firestore中,我有一个属性(名为“items”)为数组类型的文档。该数组包含具有以下结构的ShoppingItem对象: export class ShoppingItem { id?: string; name: string; checked = false; } export interface ShoppingList { id: string; name?: string; items: ShoppingItem[]; // <-- This is th

在Firestore中,我有一个属性(名为“items”)为数组类型的文档。该数组包含具有以下结构的
ShoppingItem
对象:

export class ShoppingItem {
 id?: string; 
 name: string;
 checked = false;
}
export interface ShoppingList {
 id: string;
 name?: string;
 items: ShoppingItem[]; // <-- This is the array property I am updating
}  
为了便于填写,在文件结构下方:

export class ShoppingItem {
 id?: string; 
 name: string;
 checked = false;
}
export interface ShoppingList {
 id: string;
 name?: string;
 items: ShoppingItem[]; // <-- This is the array property I am updating
}  

在数组中删除和添加项的另一个缺点是,更新的元素在UI中闪烁。

但是,无法更新对象数组的特定字段。(arrayRemove/arrayUnion)是唯一的解决方案。

如果使用相同的ref对其执行更新,是否会产生影响?不,我可以照你建议的那样做。看起来好多了(我更新了我的问题代码)。但是,为了确保arrayRemove成功并且承诺没有因为任何原因被拒绝,我仍然需要在添加对象的新值之前使用承诺“快乐路径”。但是现在代码看起来更好了,所以这可能是唯一的方法。嗯,我明白了。我想知道ref-refetch是否能实现这一点,但我猜它会对这两个更新做出反应。您是否能够通过管道传输firebase列表结果,并具有在更新存储时不会更新的“takeWhile”样式运算符?例如:将主题设置为true/false,并在firestore获取列表时使用它。我可以尝试实现这样的逻辑以防止闪烁效果。这是为我创建重复项,而不是更新数组中的原始项