简体   繁体   English

React-native get方法返回值

[英]React-native get method return value

I have the following method in my class MakeRequest.js: 我的类MakeRequest.js中有以下方法:

export default class MakeRequest{
    send() {
        var data = 'foo';
        var data2 = 'bar';
        return [data, data2];
    }
}

I am trying to access data and data2 from a different class: 我正在尝试从不同的类访问数据和data2:

(array) => MakeRequest.send(JSON.stringify(query));
alert(array[0]);

The error message displayed is 显示的错误信息是

Can't find variable: array

Why is 'array' not accessible? 为什么无法访问“数组”?

array is out of scope. array超出范围。 Your lambda ends with the send call. 您的lambda以send呼叫结束。 If you're wanting to alert within it, and not return the output of that method call, do something like this: 如果要在其中发出警报,而不返回该方法调用的输出,请执行以下操作:

(array) => {
    MakeRequest.send(JSON.stringify(query));
    alert(array[0]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM