1

我想将一个函数传递给类构造函数。该函数最终将在 onBlur 侦听器中使用。有些东西不工作。(FWIW,此代码正在“then”函数中执行 HttpRequest.getString())

这有效:

query("${_element_id}_input").onBlur.listen((e) {
  InputElement species_id = query("#id_species_id");
  species_id.value = value;
  print(species_id.value);
});

如果我将其替换为以下内容,则会出现错误:

  onBlur = ((e) {
    InputElement species_id = query("#id_species_id");
    species_id.value = value;
    print(species_id.value);
  });

  if (onBlur != null) {
    query("#{_element_id}_input").onBlur.listen(onBlur);
  }

如果我命名函数,我会得到同样的错误。错误是:

Uncaught Error: SyntaxError: Internal Dartium Exception
Stack Trace:
#0      Document.query (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/out/Release/gen/blink/bindings/dart/dart/html/Document.dart:123:128)
#1      query (dart:html:448:49)
#2      AutoComplete.AutoComplete.<anonymous closure> (package:canopy/auto_complete.dart:69:14)
#3      _ThenFuture._zonedSendValue (dart:async/future_impl.dart:371:24)
#4      _TransformFuture._sendValue.<anonymous closure> (dart:async/future_impl.dart:348:48)
#5      _ZoneBase._runInZone (dart:async/zone.dart:74:15)
#6      _ZoneBase._runUnguarded (dart:async/zone.dart:102:22)
#7      _ZoneBase.executeCallback (dart:async/zone.dart:58:23)
#8      _TransformFuture._sendValue (dart:async/future_impl.dart:348:26)
#9      _FutureImpl._setValueUnchecked (dart:async/future_impl.dart:184:26)
#10     _FutureImpl._setValue (dart:async/future_impl.dart:174:23)
#11     _FutureImpl._setOrChainValue (dart:async/future_impl.dart:336:16)
#12     _ThenFuture._zonedSendValue (dart:async/future_impl.dart:377:21)
#13     _TransformFuture._sendValue.<anonymous closure> (dart:async/future_impl.dart:348:48)
#14     _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#15     _ZoneBase._runUnguarded (dart:async/zone.dart:102:22)
#16     _ZoneBase.executeCallback (dart:async/zone.dart:58:23)
#17     _TransformFuture._sendValue (dart:async/future_impl.dart:348:26)
#18     _FutureImpl._setValueUnchecked (dart:async/future_impl.dart:184:26)
#19     _FutureImpl._asyncSetValue.<anonymous closure> (dart:async/future_impl.dart:218:25)
#20     _asyncRunCallback (dart:async/event_loop.dart:9:15)
#21     _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
#22     _Timer._Timer.<anonymous closure> (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/dart/tools/dom/src/native_DOMImplementation.dart:255:17)


Exception: SyntaxError: Internal Dartium Exception
  _DefaultZone.handleUncaughtError.<anonymous closure> (dart:async/zone.dart:146:7)
  _asyncRunCallback (dart:async/event_loop.dart:9:15)
  _asyncRunCallback (dart:async/event_loop.dart:13:7)
  _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
  _Timer._Timer.<anonymous closure> (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/dart/tools/dom/src/native_DOMImplementation.dart:255:17)
4

1 回答 1

2

罪魁祸首不是处理函数,而是您query添加侦听器的调用:

query("#{_element_id}_input").onBlur.listen(onBlur);- 缺少“$”来解决{_element_id}

于 2013-09-06T07:53:02.660 回答