Dom Google Dart:IListElement的更改事件
我想知道您是否可以监听Dom Google Dart:IListElement的更改事件,dom,dart,Dom,Dart,我想知道您是否可以监听UListElement的元素何时更改(即lieelement添加或删除) UListElement toDoList=query(“#待办事项列表”); LIElement newToDo=新的LIElement(); newToDo.text=“新任务”; toDoList.elements.add(newToDo); //将newToDo添加到toDoList后,如何执行一些代码? 我假设elements.add()是异步的,因为我来自ActionScript背景。
UListElement
的元素何时更改(即lieelement
添加或删除)
UListElement toDoList=query(“#待办事项列表”);
LIElement newToDo=新的LIElement();
newToDo.text=“新任务”;
toDoList.elements.add(newToDo);
//将newToDo添加到toDoList后,如何执行一些代码?
我假设
elements.add()
是异步的,因为我来自ActionScript背景。这是一个有效的假设吗?element.elements.add(otherElement)
是同步的,相当于Javascript(即)中的element.appendChild(otherElement)
。更高级别的框架为此提供事件,但在HTML5API级别,您必须使用MutationObserver
下面是一个可以在任何DOM元素对象上设置突变观察者的示例。然后处理程序可以根据需要处理突变事件
void setMutationObserver(Element element){
new MutationObserver(mutationHandler)
.observe(element, subtree: true, childList: true, attributes: false);
}
void mutationHandler(List<MutationRecord> mutations,
MutationObserver observer){
for (final MutationRecord r in mutations){
r.addedNodes.forEach((node){
// do stuff here
});
r.removedNodes.forEach((node){
// or here
});
}
}
void setMutationObserver(元素){
新的MutationObserver(mutationHandler)
.observe(元素,子树:true,子列表:true,属性:false);
}
void mutationHandler(列出突变,
变异观察者(观察者){
for(突变中的最终突变记录r){
r、 addedNodes.forEach((节点){
//在这里做事
});
r、 removedNodes.forEach((节点){
//还是在这里
});
}
}
您也可能对我们的MDV工作感兴趣: