在Dart中使用Jquery UI [英] use Jquery UI in Dart
问题描述
我想在Dart中创建一个简单的对话框,我认为使用现有的javascript库更容易。
这里可以找到基本示例,基本上是
I'm trying to create a simple dialog in Dart and I thought it was easier to use existing javascript libraries. Here you can find the basic example, basically
$( "#dialog" ).dialog();
在internet和stackoverflow,你可以找到1000个例子,
我想这是正确的方式:
On internet and stackoverflow you can find 1000 examples but none works to me. I suppose this is the correct way:
import 'dart:js' as js;
//[...]
var jquery = new js.JsObject(js.context['jQuery']);
var myob = jquery('#dialog').dialog();
我得到的只是这个错误:
All I get is this error:
打破异常:类'JsObject'没有实例方法调用。
Breaking on exception: Class 'JsObject' has no instance method 'call'.
Dart的文档?
推荐答案
基本上,有两个库可以与js交互:dart:js 和软件包:js a>。已在 package:js 之后创建了
Basically, there are 2 libraries to interop with js : dart:js and package:js. dart:js has been created after package:js and most of the stackoverflow answers use package:js and are still valid (it isn't worth to downvote these answers...)
package:js 提供了一个更简单的Api, (因为 package:js 使用dart:mirrors 和 noSuchMethod )。
package:js provides a simpler Api that comes at the cost of an increase of the js size (because package:js uses dart:mirrors and noSuchMethod).
package:js :
import 'package:js/js.dart' as js;
main() {
js.context.$("#dialog").dialog();
}
:js :
import 'dart:js' as js;
main() {
js.context.callMethod(r'$', ['#dialog']).callMethod('dialog');
}
这篇关于在Dart中使用Jquery UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!