简体   繁体   English

如何从API,ListView过滤数据-React-Native

[英]How to filter data from API , ListView - React-Native

i'm trying to filter data with React-Native but the info in Stackoverflow doesn't help so much. 我正在尝试使用React-Native过滤数据,但是Stackoverflow中的信息没有太大帮助。

What i have: 我有的:

ArtistListView File ArtistListView文件

I have a api-client.js file: 我有一个api-client.js文件:

const URL = 'API_URL';

function getArtists(){
return fetch(URL)
    .then(response => response.json())
    .then(data => data.topartists.artist)
    .then(artists =>artists.map(artist => {
        return {
            id: artist.mbid,
            name: artist.name,
            image: artist.image[3]['#text'],
            url: artist.url,
            likes: 400,
            comments: 200,
        }
    }))

  }

  export{ getArtists }

but i got the error 但我得到了错误

undefined is not an object (evaluating 'item.artist.toUpperCase') 未定义不是对象(评估“ item.artist.toUpperCase”)

hope that anyone can explain to me what i have wrong. 希望任何人都可以向我解释我错了。

我已经解决了,我必须将道具更改为状态...在我的Github存储库中可以找到完整的代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM