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". |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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 -