dart – 动态添加含有聚合物信号的聚合物元素会引发异常

使用Polymer,我实现了一个自定义表单,它使用polymer_signals.html来监听来自任意其他聚合物元素的更改.

它实现如下:

<link rel="import" href="packages/polymer_elements/polymer_signals/polymer_signals.html">

<polymer-element name="user-settings" extends="form">
<template>
<polymer-signals on-polymer-signalauth-changed="{{onAuth}}"></polymer-signals>
...

此元素在父聚合物元素中动态实例化,如下所示:

var userSettings = new Element.tag('form', 'user-settings');
$['main'].children.add(userSettings);

这引发了例外:

Exception: Concurrent modification during iteration: Instance(length:4) of '_GrowableList'._notify@0x1c4cf589 (http://127.0.0.1:3030/buddy/web/packages/polymer_elements/polymer_signals/polymer_signals.dart:39:12)
<anonymous closure> (http://127.0.0.1:3030/buddy/web/packages/polymer_elements/polymer_signals/polymer_signals.dart:49:12)

如果我静态地实例化聚合物形式,我不会得到这个错误.我怎么能阻止这个?

最佳答案 我无法重现你的问题.

经常会遗漏两件常见的事情

>如果您有自定义主方法
看到Polymer querySelector working on DartVM but not in Chrome after compile的答案
>在扩展DOM元素的元素的构造函数中调用super.polymerCreated().
看到Custom Polymer element extending AElement in Dart的答案

如果仍然无法解决问题,请在问题中添加更多代码(例如,用户设置元素的外观如何).

点赞