If I write the next code I get the compiler error: "Unresolved refrence:target"
jq("#element").click {
console.log(it.target)
}
However, if I print only "it" it has the property target
r.Event {originalEvent: MouseEvent, type: "click", target: button, currentTarget: button, relatedTarget: null…}
How I'm supoused to get the target then?
I suppose you use jq
from standard library, and first of all jq
from standard library is deprecated.
Then lets look at definition of click
handler:
public fun click(handler: (MouseClickEvent) -> Unit): JQuery
As you see, it
in your case is MouseClickEvent
. But MouseClickEvent
and MouseEvent
doesn't contains target
.
You can write own bindings for jquery:
import jquery.MouseClickEvent
import jquery.MouseEvent
@JsName("$")
public external fun jq(selector: String): JQuery
public external class JQuery() {
public fun click(handler: (ExtendedMouseClickEvent) -> Unit): JQuery
}
public external class ExtendedMouseClickEvent() : MouseEvent {
public val target: JQuery
public val which: Int
}
fun main(args: Array<String>) {
jq("#element").click {
console.log(it.target)
}
}
Also, you can convert existing definitions for TypeScript to kotlin.
jQuery typings: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/jquery
ts2kt: https://github.com/Kotlin/ts2kt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With