Cannot read property '$on' of undefined
See original GitHub issueI’m having a hard time catching tree events. I followed your docs (https://amsik.github.io/liquor-tree/#Events) but somehow didn’t work for me and returned an error that says “Cannot read property ‘$on’ of undefined” at this line:
this.$refs.tree.$on(e.name, this.someMethod(e))
Really appreciate your help. 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
Read more >Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >[Solved] Cannot read Properties of Undefined in JavaScript
The "Cannot read properties of undefined" error occurs when you try to access a property or a method on a variable that stores...
Read more >Node.js Cannot read property 'on' of undefined - Stack Overflow
My server.js code : var events = require('events').EventEmitter; var v = function() ...
Read more >Fix: “Cannot Read Property of Undefined” Error in JavaScript
To fix the “cannot read property of undefined” error, use the optional chaining operator on the variable before accessing a property.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@breekoy Or you could just create the tree only after obtaining of data:
Yes, this is what apparently is happening. In my case, I have 300+ objects coming from an API to be loaded to the tree component. I had the API call on the
created()
hook thinking that it would be fine. However, when themounted()
hook is invoked, tree is still loading. My guesses would be the API didn’t respond yet whenmounted()
is invoked or the objects to be loaded are huge enough to cause delay in mounting/loading the tree component.I somehow made this work by creating an async method that calls the API and call that method inside the
mounted()
hook with.then()
chained into it. Inside the function parameter ofthen()
, I called thethis.$refs.tree.setModel()
andthis.$refs.tree.$on()
.Like this:
sorry for a very late response, been kinda busy lately.