【发布时间】:2020-02-06 12:17:18
【问题描述】:
我在控制台中获取值但无法在下拉列表中显示 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} />
【问题讨论】:
-
你在哪里打电话给
setState更新的 childTrainers ? -
这就是我犯的错误。
this.setState({ CourseName : [{label: {CName}}] })如果这样做,我会出错 -
TypeError: 无法读取未定义的属性“setState”
-
请参阅stackoverflow.com/questions/59871401/…,了解如何从 Firebase 加载数据、将其设置为状态并从那里呈现数据的最小示例。
标签: javascript reactjs firebase firebase-realtime-database