基本上,我不确定为什么 firebase 在似乎是无限循环的情况下进行主动刷新。这应该是从表单获取用户输入并设置 firebase 9 数据库在点击提交按钮后有新帖子的代码
export function create() {
createForm.addEventListener('submit', (e) => {
// Initialize Firebase
e.preventDefault();
const Name = createForm["nameInput"].value;
const Description = createForm["descriptionInput"].value;
const Ingredients = createForm["ingredientsInput"].value;
const Instructions = createForm["instructionsInput"].value;
const Tags = createForm["tagInput"].value;
const File = createForm["fileInput"].files[0];
const TimeStamp = new Date().getTime();
const User = auth.currentUser;
const Uid = auth.currentUser.uid;
//insert commented out section here if need
const recipeRef = ref(db, "recipes");
const newRecipeRef = push(recipeRef);
if(User == null){
window.location.href = "login.html";
document.getElementById("create-form").reset();
}
set(newRecipeRef, {
name: Name,
description: Description,
imageURL: File,
ingredients: Ingredients,
instructions: Instructions,
tags: Tags,
timeStamp: TimeStamp,
uid: Uid,
username: User,
},
function(error){
if(error){
console.error("Error adding document: " + error);
} else {
console.long("posted to database");
alert("🍕 Form submitted successfully!");
document.getElementById("create-form").reset();
window.location.href = "displayTest.html";
}
}
);
});
console.log("it worked");
}
我现在对 firebase 不是很熟悉,这是我的第一个项目。所以我很抱歉,如果这很草率,但我也完全不知道代码是什么被赶上了
编辑:这是我遇到的错误。我忘了包括它。
捕获错误:设置失败:指定的值参数路径超过可以写入的最大深度(32)或对象在属性“recipes.-.username.proactiveRefresh.user.proactiveRefresh.user.proactiveRefresh.user.proactiveRefresh.”中包含循环。用户。主动刷新