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

getNodeByKey() does not find nodes if a numeric key is passed as number instead of string #1005

Closed
i-terezie opened this issue May 7, 2020 · 4 comments

Comments

@i-terezie
Copy link

The documentation for the getNodeByKey function does not indicate that it requires the installation of options to work:

generateIds: true,
idPrefix: "ft"-,

It would be nice to add it there.

@mar10
Copy link
Owner

mar10 commented May 7, 2020

This should not be the case: getNodeByKey() tries to lookup by html ID (which only succeeds when generateIds is true, but works independently from the idPrefix).
However it falls back to searching all nodes for a matching node.key property.

If you think you found a bug, please give more details, and I will re-open this issue.

@mar10 mar10 closed this as completed May 7, 2020
@i-terezie
Copy link
Author

getNodeByKey () works fine. The only problem is the lack of direct indication in the documentation, the need to enable generateIds: true.

@i-terezie
Copy link
Author

I realized what I had a problem. As a key, I used the ID from the database. And in one place he ended up in a string in another number. And the getNodeByKey function uses a comparison if (node.key === key) {.
When converting to a search by ID, everything is attracted to the string and works. And without it, no.
In general, not quite expected behavior. Perhaps it is worth comparing without type.

@mar10
Copy link
Owner

mar10 commented May 8, 2020

node.key must be a string (and is already converted to a string mostly).
I will add a cast to string to getNodeByKey(key) to make the method more forgiving.

mar10 added a commit that referenced this issue May 8, 2020
@mar10 mar10 changed the title Documentation for the getNodeByKey getNodeByKey() does not find nodes if a numeric key is passed as number instead of string May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants