9

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.

3 Answers 3

10

You can do :

main() {
  js.context.callMethod(r'$', ['.myClass'])
      .callMethod('myFunction', [new js.JsObject.jsify({'aKey': 'some value'})]);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Yikes. I don't suppose there's any reason to actually do this, right? Or will I be having to maintain code like this in another few years... (I mean, there's probably no advantage to using dart in a situation like this, so we probably won't see much of this kind of thing, right?)
Actually package:js provides a simpler API and you can keep on using it. See the similar question you mention. See also stackoverflow.com/questions/20590148/… for dart:js vs. package:js.
Truly acrobatic! Thanks a lot.
4

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'
    } 
}

Comments

0

How about use DQuery instead.

DQuery is a porting of jQuery in Dart.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.