我以另一种方式插入数据并在Mobile上收听。
我无法在互联网上得到答案。 这是我的脚本:
我对firebase数据库的规则
{"rules": {".read": true,".write": true}}
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
ListView,
FlatList
} from 'react-native';
import * as firebase from 'firebase';
const config = {
//MY CONFIG
}
const app = firebase.initializeApp(config)
export default class App extends Component<Props> {
constructor () {
super()
this.database = app.database().ref('users')//.child('users')
this.state = {
lists: []
}
}
componentDidMount() {
// Firebase Listener
console.log('BEGIN');
this.database.on('value', (data) => {
// data.forEach( shot => {
console.log('IN HERE', data.val());
this.state.lists.push({...data.val()})
// })
// this.setState({ lists, tasksLoading: false });
})
}
render() {
const { lists, tasksLoading } = this.state;
let taskList = ''
if (lists.length) {
taskList = <FlatList data={lists} renderItem={({item}) => <Text>{item.nama}</Text>} />;
} else {
taskList = <Text>Load</Text>
}
return (
<View style={{margin: 4}}>
{taskList}
</View>
);
}
}
帮我解决这个问题,谢谢