저는이 작업을하기 위해 며칠 동안 고생했습니다. React Native의 ListView를 Firebase 데이터베이스의 데이터로 채 웁니다. 나는이 설정을 가지고 :ReactNative ListView에 Firebase 데이터를 채우십시오.
const ListItem = require('./profileRow');
var database = firebase.database();
var userId, dataKey;
class Selection extends Component {
constructor(props) {
super(props);
userId = firebase.auth().currentUser.uid;
this.dataRef = firebase.database().ref('/users/' + userId + '/profiles_info');
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
}
listenForProfiles(dataRef){
dataRef.on('value', (snap) => {
var profiles = [];
snap.forEach((child) => {
profiles.push({
name: child.val().forename,
_key: child.key
});
});
alert(profiles);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(profiles)
});
});
}
componentDidMount() {
this.listenForProfiles(this.dataRef);
}
render() {
return (
<Image source={require('../assets/bg.png')} style={styles.container}>
<View style={{flex: 1, flexDirection:'column'}}>
<Text>
Select a profile to view:
</Text>
</View>
<View style={{flex: 1}}>
<ListView dataSource={this.state.dataSource} renderRow={this._renderItem.bind(this)} enableEmptySections={true} style={styles.listview}> </ListView>
</View>
</Image>
);
}
_renderItem(item) {
return (
<ListItem item={item}/>
);
}
}
그래서 내가 여기서 할 노력하고있어하면 "뒤따라야"각 "프로필의 문자열로의 ListView의 각 행을 채울 것입니다 "디렉토리 (0,1,2). 그러나 내 alert() 반환 된 : [object Object],[object Object],[object Object]
"profiles_info"및 각 "forename"String 해당 디렉터리에서 개체로 디렉터리를 반입하는 것을 의미합니다합니다.
이것은 내가 갇혀있는 곳입니다. 누군가가 이것에 대해 밝힐 수 있기를 바랍니다. 솔루션이 무엇인지 알아야합니다. 코드에 적용하는 방법을 모르겠습니다.
미리 감사드립니다.
Jeff에게 감사 드려요. – Benni