Skip to content

How to search in a nested array? #37

Answered by niketpathak
webVerts asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @webVerts ,

Currently, there exists no native mechanism to search within a nested array. So you are left with 2 options. Either flatten your array server-side or else you could use the transform callback to flatten your array on the fly. A naive example could be something like this -

   // typeahead-standalone setup config
   
    transform: (data) => { 
         const modifiedSource = data.source.reduce((acc, item) => {
               item.name.forEach(name => {    
                   acc.push({
                     ...item,
                     id: name, // while flattening the array, we create this field to be used as the identifier
                   })
               });

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@AlonsoK28
Comment options

@niketpathak
Comment options

@AlonsoK28
Comment options

@authifyAlly
Comment options

Answer selected by niketpathak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants