React Native和Firebase的初学者指南
2016年7月14日
大卫东 开发者倡导者您好,我叫Shoji Itagaki。 我试图让这个例子用于事件管理。 最初的例子是使用firebase数据库的杂货店。 我的意图是建立像Facebook的F8app这样的事件管理工具。
Screen1用于事件的注册管理,选择事件和注册。 屏幕2用于接待员管理,
屏幕2为空白, 它似乎无法从屏幕1转移到屏幕2
DB’s class is as follows. Event class(Event, day, start time , end time, etc) Registration class(User, Event etc)Screen 1 Outline of Firebase database management. this.itemsRef = this.getRef().child('items’); For Event Class reference pointer this.userRef = this.getRef().child('user’); For User Registration Class getRef() {return firebaseApp.database().ref();}
var user = firebase.auth().currentUser; get user account this.setState({user: user}); for render
render section mail=this.state.user.email; console.log('mail = ' + mail); mail=mail.substring(0,mail.indexOf("@")); console.log('after modify mail = ' + mail); this.userRef = firebaseApp.database().ref('user/' + mail); this.userRef.push(new User(event,password,user); This screen was OK and DB was created as follows. rera06x * -KXih12q_2XE24UQ6S7p * event: * password: * user * _key: *
title: * -KXih_ZHuf12YujhC0Bl * event * _key: * title: * password * _key: * title: * user * _key: * title: * -KXikRGmj9LTENY3yBDr * event * _key: * title: * password * _key: * title: * user * _key: * title:
Screen 2 for Receptionist and Firebase database process's outline var user = firebase.auth().currentUser; same as screen 1, to get user account componentDidMount() { this.listenForItems(this.userRef); this.userRef = firebaseApp.database().ref('user/' + mail); listenForItems(userRef) { In this section, The Registration list was get, userRef.on('value', (snap) => {
// get children as an array var user = []; snap.forEach((child) => { user.push({ event: child.val().event, _key: child.key }); }); this.setState({ dataSource: this.state.dataSource.cloneWithRows(user) }); }); } render() { return ( <ListView dataSource={this.state.dataSource} renderRow={this._renderItem.bind(this)} enableEmptySections={true} style={styles.listview}/> abridgment _renderItem(user) { const onPress = () => { Alert.alert( 'Registration', null, [ {text: 'Registration', onPress: (user) => uketukeExec }, {text: 'Cancel', onPress: (user) => console.log('Cancelled')} ] ); }; return ( <ListItem1 item={user} onPress={onPress} /> ★★★★★★★★★★★ ); } } class ListItem1 extends Component { render() { return ( <TouchableHighlight onPress={this.props.onPress}> <View style={styles.li}> <Text style={styles.liText}>{this.props.item.event}</Text> This process does not work </View> </TouchableHighlight> abridgement
任何评论将不胜感激。 商事
答案 0 :(得分:0)
最后,经过深度调试,我找到了BUG。 错误的原因是我糟糕的程序。 我的内涵很快就实现了。
无论如何,初学者指南React Native和Firebase 是这个领域最好的文章,特别是像我对Firebase的新手。
由于 商事