How to call a jQuery function from Dart?

白昼怎懂夜的黑 提交于 2019-12-18 04:45:10

问题


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.


回答1:


You can do :

main() {
  js.context.callMethod(r'$', ['.myClass'])
      .callMethod('myFunction', [new js.JsObject.jsify({'aKey': 'some value'})]);
}



回答2:


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



回答3:


How about use DQuery instead.

DQuery is a porting of jQuery in Dart.



来源:https://stackoverflow.com/questions/20755337/how-to-call-a-jquery-function-from-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!