我在控制台中获取值,但无法在下拉列表中显示 See this link
谁能解释一下我在这里做错了什么
return firebase.database().ref('Users/Trainers/').on('value', (snapshot) => {
snapshot.forEach(function(childSnapshot){
// var childKey= childSnapshot.key;
var childData= childSnapshot.val();
var childEmail = childData.email;
var childfirstName = childData.firstName;
var childlastName = childData.lastName;
var childTrainers = childfirstName + ' ' + childlastName + ' ' + childEmail;
console.log(childTrainers);
})
})
}
async componentDidMount(){
this.getlist();
}
状态
childTrainers: []
在渲染方法中,
<Select options={this.state.childTrainers} />
最佳答案
尝试从 firebase 获取值时更新状态:
return firebase.database().ref('Users/Trainers/').on('value', (snapshot) => {
const childTrainerSnapshot = snapshot.map(childSnapshot => {
return childfirstName + ' ' + childlastName + ' ' + childEmail
});
this.setState({ childTrainers: childTrainerSnapshot });
})
关于javascript - 使用 firebase 数据填充下拉字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60094812/