How to search in a nested array? #37
|
I have a situation where the json structure is as follows with the typeahead code as below I can't use it to search for "name". |
Answered by
niketpathak
Nov 8, 2022
Replies: 1 comment 4 replies
|
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 // 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
})
});
return acc;
}, []);
return modifiedSource;
},
identifier: 'id'This assumes that each string in the inner |
4 replies
Answer selected by
niketpathak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
transformcallback to flatten your array on the fly. A naive example could be something like this -