Firebase,作为键名变量 [英] Firebase, variable as key name
本文介绍了Firebase,作为键名变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上想要做的是:
variable = 'whatever';
fb.set({ variable : "More Stuff" });
因此,这将产生如下条目:
So this will result in an entry that looks like:
whatever: "More Stuff"
目前它只是结束了
variable: "More Stuff"
可以这样做吗?
推荐答案
对于最新版本的Firebase ,在变量名周围使用括号:
For the latest version of Firebase, use brackets around the variable name:
firebase.database().ref("pathName").set({[variable] : 'MoreStuff'});
使用另一种将变量索引设置为值的方法将在数据库结构。
Using the other method of setting the index of the variable to the value will create an additional layer in the database structure.
这篇关于Firebase,作为键名变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文