【发布时间】:2018-08-09 08:27:06
【问题描述】:
渲染数据后我的 Asyc 调用正在运行 我尝试在构造函数中甚至在 componentDidMount 中运行我的 Asyc 调用,但没有任何效果。
我的数据库结构..
我在 jsx 文件中的查询
for(var i = 1; i <= 6; i++) {
Firebase.database().ref('/' + i).on('value', function(snapshot) {
value[i] = snapshot.val().state;
});
}
console.log(value);
问题是我想根据我的 react native 应用程序中的数据库中的数据加载图像。
<View style={styles.container}>
<View style={styles.parent}>
// This is only one child
<TouchableOpacity style={styles.child} id='1' onPress={(event) => this.getState(event, '1')} activeOpacity={1}>
<Image style={styles.img} source={value[1]} /> // This line is not outputting any image because the array is empty
<Text style={styles.title}>LED 1</Text>
</TouchableOpacity>
// I have 6 child and want to keep the states separate for all
</View>
GetState 函数
getState (event, BtnId) {
value[BtnId] = this.state.mode_1 ? require('./img/on.png') : require('./img/off.png')
Firebase.database().ref(BtnId).update({
'state': value[BtnId]
});
}
如果您想了解更多详情,请告诉我。
【问题讨论】:
标签: javascript react-native firebase-realtime-database jsx