首页 > 解决方案 > 离子内容中的离子反应循环火力对象

问题描述

我是打字稿和firebase的新手。如何循环一个 firebase 对象,因为我无法使用 map 函数使用它。如果可能的话,我想将它转换为一个数组以便我循环它。这是我尝试过的:

const [doctors, setDoctor] = React.useState([]);


  useIonViewDidEnter(()=>{
    console.log('Enter')
    firebase.database().ref('users').orderByChild('type').equalTo('doctor').on('value',(snapshot)=>{
          // console.log(snapshot.val())
          setDoctor(snapshot.val())
          // event.detail.complete()
        })
  })

我的返回 html 看起来像

        <IonList>
        {doctors.map(elem => {
            return(
              <IonItem key={elem['uid']} onClick={getDoctors}>
              <IonLabel>
                <IonText className="font-weight: bold;">
                <h3>{elem['name']}</h3>
                </IonText>
                <h4>{elem['speciality']}</h4>
                <h4>{elem['email']}</h4>
              </IonLabel>
              <br></br>
            </IonItem> 
            )
          })}
        </IonList>

我的 Firebase 数据示例 在此处输入图像描述

我也不能使用像v-forvue js 这样的东西来直接在模板中渲染。如果有人知道我该怎么做,请随时发表评论。提前致谢!!

标签: javascriptjsonreactjsfirebaseionic-framework

解决方案


推荐阅读