ngx-typeahead icon indicating copy to clipboard operation
ngx-typeahead copied to clipboard

taListItemField doesn't handle nested items

Open juhaszPeterDev opened this issue 7 years ago • 1 comments

Hi! I did my best to understand your code and found that the 'taListItemField' option doesn't handle nested objects like {a: {b: 'foo'}} and can't reach 'b' on 'a.b' path. I found that in your /src/services/ngx-typeahead.utils.ts:109 line could be replaced from newItem = fields.reduce((acc, cur) => `${acc}${item[cur]}`, ''); to newItem = fields.reduce((acc, cur) => `${acc}${cur.split('.').reduce((prev, elem)=>{return prev ? prev[elem] : prev;},item)}`, ''); and this would handle nested object fields. I would do a pull request, but I have never done it before, that's why I'm writing here. I apologize for my inability and thank you in advance for your help.

Sidenote: did you consider that taListItemField=['a','b'], object {a: 'foo', b: 'bar'} and search 'ob' can give a false positive since you string concat all fields (in this case into 'foobar')? I know that putting a space between fields doesn't eliminate all false positives but it might reduce the numbers.

juhaszPeterDev avatar Oct 30 '18 13:10 juhaszPeterDev

taListItemField is considered to be used with a literal object only

orizens avatar Dec 06 '18 18:12 orizens