Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a jQuery function from Dart?

This is a typical situation in jQuery:

$(".myClass").myFunction({
    aKey: 'some value'
});

How do you call that using dart:js?

The documentation is a bit cryptic and a similar question that I found here seems dated.

like image 889
alearg Avatar asked Dec 24 '13 05:12

alearg


2 Answers

You can do :

main() {
  js.context.callMethod(r'$', ['.myClass'])
      .callMethod('myFunction', [new js.JsObject.jsify({'aKey': 'some value'})]);
}
like image 193
Alexandre Ardhuin Avatar answered Nov 20 '22 14:11

Alexandre Ardhuin


You can use the build-in funcitons querySelector or querySelectorAll instead of the jQuery selector. So it would be:

main(){   
    querySelector(".myClass").myFunction(){
        aKey: 'some value'
    } 
}

or for mulitple elements:

main(){
    querySelectorAll(".myClass").myFunction(){
        aKey: 'some value'
    } 
}
like image 27
XD face me Avatar answered Nov 20 '22 14:11

XD face me