你能帮我解决这个问题吗?如何在数组中设置Firebase数据库中的数据?
export class SomePage {
reg = [{apple: 201, ball: 21, cat: 12}, {apple: 202, ball: 65, cat: 15}];
constructor() {
firebase.database().ref('app/test').set({
// i want to set all ***cat*** values here like:
// key1: 12
// key2: 15
})
。
试图用这种方法提取cat
值:
let keys = this.reg.map(a => a.cat);
console.log(keys); // <unavailable>
可以使用过滤器提取猫值。 '''var catValues = reg.filter(function(item){console.log(item ['cat'])});''' – blueren
它会提取'catValues'变量的数组数据吗?它会显示控制台日志,如'this.reg.forEach((snap)=> {console.log(snap.cat)});' – Fresco
'this.reg.map(a => a.cat);'will从reg数组返回一个'cat'值的数组。你需要什么样的输出? –