【发布时间】:2015-11-06 18:31:51
【问题描述】:
我想以
的形式更新一些数据wordBank = {
{word:"aprobi", translation:"to approve", count:2},
{word:"bati", translation:"to hit, to beat, to strike", count:1},
{word:"da", translation:"of", count:1}
}
目标是能够提取和显示每个 JSON 对象中所有键的所有值。如何在 Firebase 上创建这种格式?我要使用 .update 吗?还是别的什么?
目前我只能让 firebase .update() 使用数组,但它给了我这样的数据
wordBank = [
{word:"aprobi", translation:"to approve", count:2},
{word:"bati", translation:"to hit, to beat, to strike", count:1},
{word:"da", translation:"of", count:1}
];
其中每个词对象是数组中的一个索引。
这是我构建 wordObjects 的方式:
function getWords() {
if (document.getElementsByClassName("vortarobobelo").length != 0){
var words;
words = document.getElementsByClassName("vortarobobelo")[0].children[0].children;
for (var i =0; i < words.length; i++) {
var localBank = {} //creating the local variable to store the word
var newWord = words[i].children[0].innerText; // getting the word from the DOM
var newTranslation = words[i].children[1].innerText; // getting the translation from the DOM
localBank.word = newWord;
localBank.translation = newTranslation;
localBank.count = 0 //assuming this is the first time the user has clicked on the word
console.log(localBank);
wordBank[localBank.word] = localBank;
fireBank.update(localBank);
}
}
}
【问题讨论】:
标签: firebase