Call JQuery Eventhandler


#1

How can i call a member function for a jQuery Eventhandler ?

import jquery.jq

class Test
{
init{
println(“Init Test”)
jq().ready{myReady()}
}

fun myReady(){
println(“Ready Callback!”)
}
}

I got following Error:

Uncaught TypeError: this$Test.myReady is not a function


#2

There are too many ways and setups to make this work. I can’t tell you what is wrong in your code, because I don’t know what your setup is? Do you bind jQuery as a library via @JsModule/external?


#3

In my HTML the jQuery is loaded via Script, in Kotlin i use the Standard Library.


#4

What module loading library are you using in JavaScript? Or are you using no module loader?


#5

I use no Module Loader. The Document ready Event is called. If i use a println("") directly it works, but it looks to me that the “this” is not available.

This works: jq().ready{ println(“Callback called”)}

but not calling a Member function.


#6

Where and how do you create an object of your Test class?


#7

In HTML Java Script:


#8

<script>
console.log(“START”);
$(document).ready(function ()
{
console.log(“document loaded”);
let test = Portal.Test();
});
</script>


#9

Got it :joy:

I have instantiate the Test class with new Test() in my Script. So i was operation on the Class itself instead of an Instance.

Sorry for that :sleepy: