我有一个简单的Web应用程序,允许您创建项目列表(存储为对象),然后将这些项目存储在firebase数据库中。我目前使用set方法而不是push。这是最好的方法吗?或者我应该使用推?如果我想在Web应用程序和firebase中更新值,那该怎么办?当前的代码片段如下所示:
//on clicking save in deck create modal, creating deck and selecting it for editing
$('.save').on('click', function () {
var deckName = $("#createDeck").val().trim();
var authorName = $("#addAuthor").val().trim();
var dClass = $("#Deck-class").val();
if (dClass != null && deckName != "" && authorName != "") {
selectedDeck = new UserDeck(deckName, authorName, dClass);
$("#currentDeckDisplay").html("Current Deck: " + selectedDeck.name);
$("#upvotedCount").html("Upvoted: " + selectedDeck.upvotes);
$("#downvotedCount").html("Downvoted: " + selectedDeck.downvotes);
database.ref('decks/' + selectedDeck.deckId).set({
selectedDeck
});
$('.mainRow').empty();
drawCards();
}
else {
alert("Need to fill in deck information");
}
});