Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React Native-在另一个函数中无法识别函数_Javascript_Firebase_React Native_Firebase Storage - Fatal编程技术网

Javascript React Native-在另一个函数中无法识别函数

Javascript React Native-在另一个函数中无法识别函数,javascript,firebase,react-native,firebase-storage,Javascript,Firebase,React Native,Firebase Storage,我正在使用Firebase实时存储。我试图从firebase ref.on()函数内部调用函数 我的代码: export default class HomeScreen extends React.Component { constructor(props) { super(props); ref.on("value", function (snapshot) { dosomething(snapshot.val()) //<-- not recogn

我正在使用Firebase实时存储。我试图从firebase ref.on()函数内部调用函数

我的代码:

export default class HomeScreen extends React.Component {

  constructor(props) {
    super(props);

    ref.on("value", function (snapshot) {
      dosomething(snapshot.val()) //<-- not recognized
    }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
    });
   } 

  dosomething(val){
    //...
  }

  //....
});
导出默认类主屏幕扩展React.Component{
建造师(道具){
超级(道具);
参考“值”,功能(快照){

dosomething(snapshot.val())/您需要将
函数(snapshot){
更改为
(snapshot)=>{

现在,该回调中的
this
是包含词法上下文的
this
值,即构造函数

然后您可以使用
this.dosomething
——因为
dosomething
this

export default class HomeScreen extends React.Component {

  constructor(props) {
    super(props);

    ref.on("value", (snapshot) => {
      this.dosomething(snapshot.val())
    }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
    });
   } 

  dosomething(val){
    //...
  }

  //....
});

您需要将
函数(快照){
更改为
(快照)=>{

现在,该回调中的
this
是包含词法上下文的
this
值,即构造函数

然后您可以使用
this.dosomething
——因为
dosomething
this

export default class HomeScreen extends React.Component {

  constructor(props) {
    super(props);

    ref.on("value", (snapshot) => {
      this.dosomething(snapshot.val())
    }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
    });
   } 

  dosomething(val){
    //...
  }

  //....
});