JavaScript - 按键访问Firebase数据

时间:2018-06-14 07:31:44

标签: javascript firebase firebase-realtime-database

Firebase data structure

我使用React和Firebase 我想要检索名为" Phone"的数据。有没有办法检索它? 当我在console.log时,我只能得到"用户"

const ref = firebase.database().ref('Users');
  ref.once("value").then(function(snapshot) {
  let key = snapshot.child(this.state.username).val();; 
  console.log(key);
});

1 个答案:

答案 0 :(得分:0)

这是获得标题的一种方法:

    const pressButton1 = () => {

const MyView = Mn.View.extend({
  template: _.template('<div><input type="button" value="Click me to see Component 1" onclick="pressButton1()" id="first-region" /></div>'),
  regions: {
    firstRegion: '#first-region',
    secondRegion: '#second-region',
    thirdRegion: '#third-region',
  }
});

const myView = new MyView();
myView.render();
$('body').append(myView.$el);

let loadView = require('./components/cmp1/view').default
console.log(loadView)
myView.getRegion('firstRegion').show(new loadView())

//$(document).foundation();

};

pressButton1();

如果您是Firebase的新用户,我建议您使用Firebase codelab for web developers,其中包含此主题和许多其他主题。