Search Filter with React Native on FlatList

前端 未结 10 1208
孤街浪徒
孤街浪徒 2020-12-28 08:33

I am trying to search through a flatlist based on a search bar text. The problem I am running into is that when the user mistypes...say they wanted to type \"burger\" but ty

10条回答
  •  攒了一身酷
    2020-12-28 08:50

    Do filter by applying

    let filterData= data.filter((item) => {
      return item.name.toLowerCase().match(text)
    })
    if (!text || text === '') {
      this.setState({
        datasource: initial
      })
    } else if (!Array.isArray(filterData) && !filterData.length) {
      // set no data flag to true so as to render flatlist conditionally
      this.setState({
        noData: true
      })
    } else if (Array.isArray(filterData)) {
      this.setState({
        noData: false,`enter code here`
        dataSource: filterData
      })`enter code here`
    }
    

提交回复
热议问题