【问题标题】:compiled dart code not running in IE 10 and IE 11已编译的 dart 代码未在 IE 10 和 IE 11 中运行
【发布时间】:2015-08-04 04:31:25
【问题描述】:

我在使用一个小型 dart 应用程序时遇到了问题,该应用程序在 Chrome 和 Firefox 中运行得非常好……猜猜看……在 IE 10 和 11 中没有(Win10 Preview 中的 Project Spartan 有效!)。

这是一个简单的 UI 控制逻辑,如下所示:

...
//init elements
SelectElement studyList = querySelector('#studies');
SelectElement roleList = querySelector('#roles');
SelectElement siteList = querySelector('#sites');
ButtonElement createButton = querySelector('#create');

//Kick in the UI logic
_populateStudies();

//UI logic
_populateStudies() {
  for (var study in studies) {
    OptionElement option = new OptionElement();
    option.text = study;
    studyList.children.add(option);
  }
  for (OptionElement element in studyList.children) {
    throw new Exception("ADDING_HANDLER");

//以下执行,handler好像挂了

    element.onClick.listen(_studyClickHandler);
  }
}

//从此不再在IE中执行

_studyClickHandler(Event e) {
  siteList.children.clear();
  roleList.children.clear();
  _populateRoles();
}

_populateRoles(){
  List<String> roles = context.getRolesFor(studyList.selectedOptions[0].text);
  for (var role in roles) {
    OptionElement option = new OptionElement();
    option.text = role;
    roleList.children.add(option);
  }
  for (OptionElement element in roleList.children) {
    element.onClick.listen(_roleClickHandler);
  }
}
...

在 IE 中,第二个选择框保持为空。 Chrome 和 Firefox 按预期处理代码,根据在第一个选择框中选择的元素填充框的子项。 我不知道问题出在哪里...我将处理程序重构为匿名函数

onClick.listen((_){
  handle stuff
});

控制台根本没有显示错误。 也许有一个简单的解决方案,但我对飞镖比较陌生,无法弄清楚?

谢谢

【问题讨论】:

  • 请添加一个代码示例,其中包含我们可以在浏览器中运行的所有代码。
  • 这取决于 AJAX 调用获取的数据。我将尝试对其进行一些模拟并发布一段代码......

标签: dart internet-explorer-10 internet-explorer-11 dart2js


【解决方案1】:

我猜你提到的浏览器中的&lt;option&gt; 不支持click 处理程序注册。或者,您可以在 SelectElement.onChange 上注册您的回调并使用以下内容检索所选内容:

import 'dart:html';
void main() {
  SelectElement select = querySelector('select');
  select.onChange.listen((_) {
    final opt = select.options[select.selectedIndex];
    print(opt.value);
  });
}

您可以使用这些浏览器try it on DartPad

【讨论】:

  • 非常感谢!这解决了我的问题。还有一个问题:在这种情况下,是我还是 IE 不遵守约定? ;-)
猜你喜欢
  • 2016-07-27
  • 1970-01-01
  • 2013-12-01
  • 2014-04-29
  • 1970-01-01
  • 2014-10-28
  • 2016-08-13
  • 1970-01-01
  • 2017-09-05
相关资源
最近更新 更多