[英]Use passed parameters in for loop - React Native
我有兩節課。 在第一個中,我從API獲取。 然后,我使用props.navigation將數據傳遞給另一個類。 我可以顯示數據,但是我想在For循環中使用這些數據,如以下代碼所示:
renderText = () => {
const obje = this.props.navigation.state.params.item;
Console.log(obje) //this prints correctly
for (let i = 0; i < obje.length; i++) {
console.log(obje) //this doesnt print anything
if (obje[i].name != null) {
console.log(obje}
}
}
編輯:當我嘗試打印const obje
,它會打印。 但是,當我嘗試打印obje
for循環它不里面,所以我想它甚至沒有經歷的for循環的。
嘗試這種方式:
renderText = () => {
const obje = this.props.navigation.state.params.item;
console.log(obje) //this prints correctly
Object.keys(obje).map((item) => {
if(item == 'name'){
console.log(obje[item])//YOU CAN PRINT NAME'S VALUE LIKE THIS
}
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.