如何将数组传递给消防站arrayUnion() 函数
当我试图传递一个数组时,我会得到这个错误。
误差
Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
示例
let myArray = ["1", "2", "3"];
docRef.update({
test: firebase.firestore.FieldValue.arrayUnion(myArray)
});发布于 2018-11-11 19:15:37
Function.prototype.apply()示例
let myArray = ["1", "2", "3"];
docRef.update({
test: firebase.firestore.FieldValue.arrayUnion.apply(this, myArray)
});ECMAScript 6示例
let myArray = ["1", "2", "3"];
docRef.update({
test: firebase.firestore.FieldValue.arrayUnion(...myArray)
});当使用上述任何一种方法传递数组时,Firestore只会向Firestore数组中不存在的数组元素添加新的数组元素。
例如,运行上面的代码,然后运行以下命令
let myArray = ["2", "3", "5", "7"];
docRef.update({
test: firebase.firestore.FieldValue.arrayUnion(...myArray)
});只会将"5“和”7“添加到Firestore中的数组中。这也适用于对象数组。
https://stackoverflow.com/questions/53252265
复制相似问题