[英]Can't assign new value in array in Firebase cloud function
我的 Firebase function 出现问题,我从 Firestore 获取一个集合,并尝试在 nodejs 中本地更改其值(不将其上传回 Firestore),但该值保持不变,try/catch 未返回任何错误. 这是我的代码:
function setValueInArray(indexArray, array) {
console.log("SetValueInArray");
for (var index of indexArray) {
console.log(array[index].data().value); // **Logs false**
console.log("_________");
array[index].data().value = true;
console.log(array[index].data().value); // **Logs false**
}
}
您不能修改data()
方法返回的 Object。 您必须将其分配给新的 Object,如下所示:
function setValueInArray(indexArray, array) {
console.log('SetValueInArray');
for (var index of indexArray) {
var newObj = array[index].data();
console.log(newObj.value); // **Logs false**
newObj.value = true;
console.log(newObj.value); // **Logs true**
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.