Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taListItemField doesn't handle nested items #30

Open
juhaszPeterDev opened this issue Oct 30, 2018 · 1 comment
Open

taListItemField doesn't handle nested items #30

juhaszPeterDev opened this issue Oct 30, 2018 · 1 comment
Labels

Comments

@juhaszPeterDev
Copy link

juhaszPeterDev commented Oct 30, 2018

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.

@orizens
Copy link
Owner

orizens commented Dec 6, 2018

taListItemField is considered to be used with a literal object only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants