简体   繁体   English

undefined 不是 function ('...this.state.dataBanner.map...'附近)

[英]undefined is not a function (near '...this.state.dataBanner.map...')

I have already checked some similar questions with the same problem: ReactJS TypeError: undefined is not a function (near '...this.state.data.map...') I have already checked some similar questions with the same problem: ReactJS TypeError: undefined is not a function (near '...this.state.data.map...')

I have followed each of the steps: dataBanner:[] and dataBanner:responseJson我已按照每个步骤操作: dataBanner:[]dataBanner:responseJson

...
import Swiper from 'react-native-swiper'
...
constructor(props){
    super(props);
    this.state = {
        dataNews:[],
        dataBanner:[]
    }
}
componentDidMount(){
    return fetch(baseUrl)
    .then((response)=> response.json())
    .then((responseJson)=>{
        console.log(responseJson)
        this.setState({
            dataNews:responseJson,
            dataBanner:responseJson
        })
        //console.log(responseJson)
    })
    .catch((error)=>{
        console.log(error)
    })
}

But the following code still gives me an error:但是下面的代码仍然给我一个错误:

            <Swiper>
                {this.state.dataBanner.map((itemImg)=>{
                    return (
                        <Image
                            source ={{ uri: itemImg.urlToImage }}
                            style ={{height:"100%", width:"100%"}}
                        />
                    )
                })}
            </Swiper>

在此处输入图像描述

You can try你可以试试

        this.setState({
            dataNews:responseJson?.articles, // add articals here
            dataBanner:responseJson?.articles // add articals here
        })
   

and also you can validate你也可以验证

<Swiper>
    {this.state.dataBanner?.length > 0 && this.state.dataBanner.map((itemImg) => {
        return (
            <Image
                source={{ uri: itemImg.urlToImage }}
                style={{ height: "100%", width: "100%" }}
            />
        )
    })}
</Swiper>



 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 undefined 不是 function ('...this.state.results.map...' 附近) - undefined is not a function (near '…this.state.results.map…') 未定义不是 function(靠近'... map ...') - Undefined is not a function (near '… map …') TypeError:undefined不是this.state.cafes.map附近的函数 - TypeError: undefined is not a function near this.state.cafes.map TypeError: undefined is not a function ('...this.state.profile.map...'附近) - TypeError: undefined is not a function (near '…this.state.profile.map…') React Native TypeError: undefined is not a function (near &#39;...this.state.clubs.map...&#39;) - React Native TypeError: undefined is not a function (near '...this.state.clubs.map...') TypeError: undefined is not a function ('...this.state.categories.map...'附近) - TypeError: undefined is not a function (near '…this.state.categories.map…') React Native Webscraping Attempt:undefined 不是一个函数(靠近 &#39;...this.state.items.map...&#39;) - React Native Webscraping Attempt: undefined is not a function (near '...this.state.items.map...') TypeError: undefined is not a function(靠近“…dataSource.map…”) - TypeError: undefined is not a function (near “…dataSource.map…”) undefined 不是 function(靠近'...movies.map...') - undefined is not a function (near '...movies.map...') React-Native TypeError:未定义不是函数(在“ ... this.state.feeds.map ...”附近) - React-Native TypeError: undefined is not a function (near '…this.state.feeds.map…')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM