第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

收到的道具在本機導(dǎo)航中未定義

收到的道具在本機導(dǎo)航中未定義

阿晨1998 2021-11-25 19:16:36
我正在嘗試訪問傳遞給本機組件的道具,但該組件似乎未收到道具。傳遞 props(PastHires.js) 的組件:return (  <ScrollView style={styles.container}>    <Text style={styles.heading}>Past Hires</Text>      {        this.state.boards.filter(item => item.driverId === this.props.user.id && item.hireStatus === 'completed' ).map((item, i) => (          <ListItem            style={styles.listItem}            key={i}            title={item.pickupDatetime + '  ' + item.hireType.toUpperCase() + '  ' + item.pickupLocation.toUpperCase()}            leftIcon={{name: 'book', type: 'font-awesome'}}            onPress={() => {              this.props.navigation.navigate('PastHireDetails', {                hireId: 12,              });            }}          />        ))      }  </ScrollView>);}接收道具的組件(PastHireDetails.js):componentDidMount() {const { navigation } = this.props;// console.log(navigation.state)const ref = Firebase.firestore().collection('hires').doc(JSON.parse(navigation.getParam('hireId')));ref.get().then((doc) => {  if (doc.exists) {    this.setState({      hire: doc.data(),      key: doc.id,      isLoading: false    });  } else {    console.log("No such document!");  }});}這會引發(fā)語法錯誤:JSON Parse Error: Unexpected identifier "undefined" When I console log navigation.state 它返回該參數(shù)未定義Object {  "key": "PastHireDetails",  "params": undefined,  "routeName": "PastHireDetails",}我在這里做錯了什么嗎?任何修復(fù)?
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻1812條經(jīng)驗 獲得超5個贊

如果你使用了 react-navigation,試試這個來訪問導(dǎo)航參數(shù)


 componentDidMount() {

    const { navigation } = this.props;

    // console.log(navigation.state);

    const hireId = navigation.state.params.hireId;

    const ref = Firebase.firestore().collection('hires').doc(hireId);

    ref.get().then((doc) => {

      if (doc.exists) {

        this.setState({

          hire: doc.data(),

          key: doc.id,

          isLoading: false

        });

      } else {

        console.log("No such document!");

      }

    }); 

 }

并參考這個類似的問題 https://stackoverflow.com/questions/58279318/navigation-getparam-in-not-an-object/58280498#58280498


查看完整回答
反對 回復(fù) 2021-11-25
?
一只名叫tom的貓

TA貢獻1906條經(jīng)驗 獲得超3個贊

this.props.navigation.navigate('PastHireDetails', {

                hireId: 12,

              })

在上面的行中,您設(shè)置了一個名為hiringId 的導(dǎo)航參數(shù),它是一個整數(shù)


const { navigation } = this.props


navigation.getParam('hireId')

navigation.getParam('hireId') 將返回一個整數(shù)值


但是在另一個腳本中,您可以通過以下方式將該整數(shù)轉(zhuǎn)換為 JSON JSON.parse(navigation.getParam('hireId'))


這會給你一個錯誤


嘗試刪除 JSON.parse 因為它已經(jīng)是您想要的整數(shù)


查看完整回答
反對 回復(fù) 2021-11-25
  • 2 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號