How to get data from events with jayq in Clojurescript?
-
11-06-2021 - |
Question
I'm trying to get modifer key data from an event with jayq (see here).
This works just fine
(delegate $body note-list-item :click
(fn [e]
(.preventDefault e)
(js/alert "clicked!")))
But this doesn't.
(delegate $body note-list-item :click
(fn [e]
(.preventDefault e)
(if (.metaKey e)
(js/alert "meta clicked")
(js/alert "no meta"))))
The Javascript console in Chrome gives me Uncaught TypeError: Property 'metaKey' of object #<Object> is not a function
Solution
And then I immediately figured it out, of course. metaKey
is a property of the object, not a method. In Clojurescript you get it with (.-metaKey e)
(note the dash). See here for more details.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow