本文介绍了在Dart为什么下面的代码(关于MutationObserver)不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我修改了一个Dart聚合的例子来测试MutationObserver。这是行不通的!任何建议?
I modified one the Dart polymer example to test MutationObserver. It does not work! Any suggestion?
这是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!!!!!!!!!!!**
}
有什么想法为什么它不工作?
Any idea about why it would not work?
[注意:网页显示正常,问题只在于MutationObserver]
[Note: The webpage display is fine, problem is just about the MutationObserver]
p>
推荐答案
我想你不想在#tmpl上监听,而是在其parentNode上监听。当设置模型时,HTML模板元素将其内容展开为同级。尝试此更改:
I think you don't want to listen on #tmpl, but on its parentNode. HTML Template element expands its contents as siblings when a model is set. Try this change:
observer.observe(query('#tmpl').parent, childList: true, subtree: true);
这篇关于在Dart为什么下面的代码(关于MutationObserver)不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!