简体   繁体   English

jQuery和Dart与call()互操作

[英]jQuery and Dart interop with call()

I'm trying to make basical jQuery interop with Dart in order to use jQuery plugins easily. 我试图与Dart进行基本的jQuery互操作,以便轻松使用jQuery插件。

I'm trying to figure out a way of achieving both the classical $("#elementID") DOM query selection and the plugins getters of $.fn.pluginX.methodY() 我试图找出一种方法来实现经典的$("#elementID") DOM查询选择和$.fn.pluginX.methodY()的插件$.fn.pluginX.methodY()

So far I have developed this 到目前为止,我已经开发了

@JS()
external JQuery jQuery(String query);

@JS("jQuery")
abstract class JQuery extends intlTelInput.JQuery {
  factory JQuery() {}
  external static Plugins get fn;
}

So I can achieve JS $("#elementID") with Dart jQuery("#elementID") and JS $.fn.pluginX.methodY() with Dart JQuery.fn.pluginX.methodY() 因此,我可以使用Dart jQuery("#elementID")和JS $.fn.pluginX.methodY()使用Dart JQuery.fn.pluginX.methodY()实现JS $("#elementID") JQuery.fn.pluginX.methodY()

But I would like to achieve JQuery("#elemID") with something in the class, having the final code sorta like: 但是我想用类中的某些东西来实现JQuery("#elemID") ,最终的代码排序如下:

@JS("jQuery")
abstract class JQuery extends intlTelInput.JQuery {
  factory JQuery() {}
  external static JQuery call(String query); // <- this replacing jQuery(..)
  external static Plugins get fn;
}

Add a static method named call to a Dart class won't make JQuery callable. 在Dart类中添加名为call的静态方法不会使JQuery可调用。 Good news is you can achieve the same effect you should just make jQuery a getter that returns a JS interop object that is callable. 好消息是,您可以实现相同的效果,只需使jQuery成为可返回可调用JS互操作对象的getter。

Try this instead: 尝试以下方法:

    @JS("jQuery")
    external JQuery get jQuery;

    @JS() @anonymous
    abstract class JQuery extends intlTelInput.JQuery {
      external JQuery call(String query);
      external Plugins get fn;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM