無法讀取的未定義的屬性「數據」我有以下的雲功能:火力地堡雲功能 - 類型錯誤:當數據存在
exports.keepPostKeysUpdated = functions.database.ref('/posts/{postid}').onWrite(event => {
console.log("write on posts...");
console.log(event.previous.params.postID);
console.log(event.data.previous.val());
console.log(event.data.previous.val().postID);
var postKey = event.data.previous.val().postID;
// When a table, category, or region is changed the old upload has to be deleted
if (event.data.previous.exists()) {
if (event.data.previous.val().table != event.data.val().table || event.data.previous.val().region !=
event.data.val().region || event.previous.data.val().category != event.data.val().category) {
// category, region, or table was changed
console.log(postKey);
if (event.data.previous.val().table != event.data.val().table) {
console.log("Table was changed");
// delete the post from the old table
const oldTable = event.data.previous.val().table;
const newTable = event.data.val().table;
addToNewTable(newTable, postKey);
removePostFromOldTable(oldTable, postKey);
}
if (event.data.previous.val().category != event.data.val().category) {
console.log("Category was changed");
// delete the post from the old category
const oldCategory = event.data.previous.val().category;
const newCategory = event.data.val().category;
addToNewCategory(newCategory, postKey);
removePostFromOldCategory(oldCategory, postKey);
}
if (event.data.previous.val().region != event.data.val().region) {
console.log("Region was changed");
// delete post from old region
const oldRegion = event.data.previous.val().region;
const newRegion = event.data.val().region;
addToNewRegion(newRegion, postKey);
removePostFromOldRegion(oldRegion, postKey);
}
}
else {
return
}
}
else {
// previous value does not exist this case is handled by
// copyPostKey
return
}
});
當一個表或區域被改變它的工作完全正常,但無法每次類別被改變。錯誤來自行var postKey = event.data.previous.val().postID;
這個值如何被讀取一些而不是其他的?我甚至可以通過控制檯登錄密鑰,但是當我嘗試將其分配給postKey時,它表示無法讀取密鑰。任何想法這個問題是從什麼?
的數據總是從我的iOS應用
ref.child("posts").child(editedPost.postID).updateChildValues(["table": editedPost.table])
ref.child("posts").child(editedPost.postID).updateChildValues(["category": editedPost.category])
ref.child("posts").child(editedPost.postID).updateChildValues(["region": editedPost.region])
節點= v6.11.2 火力工具編寫同樣的方式= 3.10.10