Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

javascript - Listening for event in Dart via JQuery "on"

I am using a Bootstrap Modal dialog in Dart via js interop. All works OK apart from listening for the custom events. I am trying to listen to the "shown" event using the following code:

js.scoped(() {
  js.context.jQuery("#myModal").on("shown", new js.Callback.once(() {
    print("Dialog Shown");         
  }));
});

However, I get the following Dart error when the event is fired:

Class '() => dynamic' has no instance method 'call'.

NoSuchMethodError : method not found: 'call'
Receiver: Closure: (dynamic) => dynamic
Arguments: [Instance of 'Proxy']

Any ideas what I'm doing wrong?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You get this error because the callback should have one parameter (handler parameter of on documentation take a eventObject parameter). So your code should be :

js.context.jQuery("#myModal").on("shown", new js.Callback.many((eventObject) {
  print("Dialog Shown");
}));

Note also the use of js.Callback.many instead of js.Callback.once. The former allows the callback to be called several times.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...