如何更新本机的全局变量值?

时间:2019-05-06 09:05:20

标签: javascript reactjs react-native global-variables local-variables

我想更新bjpv的值,最后将其状态设置为新的更新状态,这将从firebase函数中获得

我将expo用于本机应用程序。这是一个简单的投票应用程序。

class Dashboard extends React.Component {
constructor(props){
    super(props)
    this.state = ({
        name: '',
        bjp:'',
    })
    this.componentDidMount=()=>{
        var bjpv;
        console.log("var bjpv loaded")
        firebase.database().ref("candid/BJP").once('value').then(function(snapshot){
            ping = snapshot.val().votes;
            // return bjpv;
            console.log("Start firebase");
            console.log(bjpv);
            console.log(ping);
            this.setState.bjpv = this.setState.ping;
            console.log("Closing firebase")
        })
        console.log("No fire");
        console.log(bjpv);
        console.log("End message")
        this.setState(function(state, props){
            console.log("Hello")
            return {
                bjp: bjpv,
            }
        })
}
}

我想访问此const数组中的值

var data = [
    { name: 'BJP', votes : this.state.bjp, color: 'pink', legendFontColor: '#7F7F7F', legendFontSize: 10 }]

我想最终更新从firebase获取的var数据中的表决值。

1 个答案:

答案 0 :(得分:0)

我尝试了解您的代码。这是你的意思吗?

$productQuery = ...; // complex query comes from another class

return CategoryModel::whereHas('products', function ($query) use($productQuery) {
    $query->apply($productQuery) // I need to apply product query here but Laravel has not this method
})->get();