【发布时间】: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