0

I have search bar in react native to filter json object. This is my code:

SearchFilterFunction(text){

newData = this.arrayholder.filter(function(item){


   itemdata= item.Nome.toUpperCase(), //How itemdata have item.nome and item.citta?

   textData = text.toUpperCase() 
    return itemdata.indexOf(textData) > -1
  })
 this.setState({

  dataSource: this.state.dataSource.cloneWithRows(newData),
  text: text

})

And this is my json:

15:11:29: Array [
15:11:29:   Object {
15:11:29:     "Citta": "Milano",
 15:11:29:     "Data": "9/08/2018 ",
15:11:29:     "Foto": "x",
15:11:29:     "Nome": "Musica pop",
15:11:29:     "Ora": "18:30:00",
15:11:29:   },
15:11:29:   Object {
15:11:29:     "Citta": "Ancona",
15:11:29:     "Data": "9/05/2018",
15:11:29:     "Foto": "x",
15:11:29:     "Nome": "Food porn",
15:11:29:     "Ora": "21:30:00",
15:11:29:   },
15:11:29:   Object {
15:11:29:     "Citta": "miami",
15:11:29:     "Data": "12/12/2018",
15:11:29:     "Foto": "x",
 15:11:29:     "Nome": "musica jazz",
 15:11:29:     "Ora": "21:30:00",
 15:11:29:   },
 15:11:29: ]

How can I filter this object by Nome and Citta? I dont need only item.Nome

4
  • You need to iterate each Object and search for index Nome or Citta Commented May 11, 2018 at 13:35
  • I know but How? can u show me a code Commented May 11, 2018 at 13:42
  • Check this post Commented May 11, 2018 at 13:54
  • This is not what I want, I use Search Box that filters item.. in this case only by Nome.. I need to filter by Nome AND Citta Commented May 11, 2018 at 14:12

1 Answer 1

0

You can change your filter code to below code to search text in both Nome and Citta

itemdata= item.Nome.toUpperCase();
itemCitta = item.Citta.toUpperCase();
textData = text.toUpperCase() 
return itemdata.indexOf(textData) > -1 || itemCitta.indexOf(textData) > -1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.