【问题标题】:How to disable page based on database(firebase) query?如何禁用基于数据库(firebase)查询的页面?
【发布时间】:2019-05-18 04:04:23
【问题描述】:

我是 react 和 firebase 的新手,目前正在开发和应用作为我最后一年的项目

问题:

我的应用程序中有两个页面 PAGE 1 & PAGE2 , 我想禁用第 1 页,直到第 2 页输入数据(安装应用时应仅检查初始记录)

代码:

第 1 页内的代码

componentDidMount() {
firebase.database().ref(`/users/${awcid}/Timeline/Page2/`)
     .orderByChild('Page2date')
     .limitToLast(1)
     .once('value', checkifexists => {
       const datafff = firebaseLooper(checkifexists);
       console.log("checkifexists", datafff.length);
        const temp=datafff.length;
       if ((temp >= 1)) {
         this.setState({
           checkifexists: temp
         });
         console.log( "--------checkifexists--------","IF CONDITION",this.state.checkifexists, "----------------");
       } else {
         this.setState({
           checkifexists: 0
         });
         console.log("ELSE CONDITION");
       }
     });
}

内部渲染

   {!(parseInt(this.state.checkifexists) >= parseInt(1)) ? 
 <View style={styles.notexists} >
<Text style={{ color: '#FFFFFF', textAlign: 'center', alignItems: 'center', }}>Please enter stock page initially to access this page{'\n'}</Text>
</View> :
         :<View><Text>Display the form</Text></View>}

此代码运行良好,但每次加载 page1 时都会检查(而不是最初检查)

【问题讨论】:

    标签: firebase react-native firebase-realtime-database


    【解决方案1】:

    您必须保留一个标志来识别应用程序是否在安装后首次运行。您可以使用react-native-async-storage 将字段存储为“isNotFrsttime”,并在第一次运行后将其设置为 true。还要确保包含该布尔检查以仅在初始应用运行时阻止您的视图。

    否则,如果您使用的是 redux,您可以保持您的 redux 状态并在应用启动时补充水分。如果您已经在项目中实现了 redux,则可以将标志存储在 redux 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-03
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 2017-10-13
      • 2021-11-14
      相关资源
      最近更新 更多