dom – 在Dart中为什么下面的代码(关于MutationObserver)不起作用?

修改一个Dart聚合物示例来测试MutationObserver.这是行不通的!有什么建议吗?

这是HTML代码

<body>   
<ul>      
  <template id="tmpl" repeat>
    <li>{{}}</li>
  </template>
</ul>
</body>

这是Dart代码

MutationObserver observer = new MutationObserver(_onMutation);
observer.observe(query('#tmpl'),childList: true,subtree: true); 
List timestamps = toObservable([]); 
query('#tmpl').model = timestamps;

new Timer.periodic(const Duration(seconds: 1),(_) {
    timestamps.add(new DateTime.Now());
});

_onMutation(List<MutationRecord> mutations,MutationObserver observer) {
 print('hello test MutationObserver');  **//there is not any print!!!!!!!!!!!**
}

知道为什么它不起作用的任何想法?

[注意:网页显示很好,问题只是关于MutationObserver]

谢谢!

解决方法

我想你不想听#tmpl,但是在它的parentNode上.在设置模型时,HTML Template元素将其内容扩展为兄弟姐妹.试试这个改变:
observer.observe(query('#tmpl').parent,subtree: true);

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些