html - 在 Dart 中如何查询嵌套模板中的元素?

标签 html dom asynchronous dart

我在 Dart 中有一些嵌套模板,如下所示:

<template id="id1">
<template id="id2">
<input type= id={{xxx}}>
</template>
</template>

这种情况下,如何查询输入元素呢?我尝试了嵌套 Timer.run 但它不起作用。

query("#id1").model = xxxx
Timer.run({ query("#id2").model=xxxxx;
   Timer.run({ print(query(xxx));});
});

有人有什么建议吗?

谢谢!

================================================== =========================

注意:嵌套模板实际上是在一个表格中,代码如下:

    <div style="cursor:crosshair; -webkit-user-select: none; user-select: none;">
    <table id="base_table" style="border-collapse:collapse; position: absolute; top:200px; left:200px; width:800px; height:400px" border="2">
    <template id="table" repeat>  
    <tr>
    <template id={{id}} repeat>  
    <td>  <label style="border:0px; height:18px; width:80px" id={{Cell_ID}}> {{Cell_data}} </label> </td>
    </template>
    </tr>
    </template>
    </div>

最佳答案

你最好的选择是使用 MutationObserver:

final observer = new MutationObserver(() {
  ... code here ...

  observer.disconnect();
})..observe(node, childList: true, subtree: true);

很快,该方法将在 PolymerElement 中可用:

onMutation(() => ... code here ...);

它会自动断开观察,如上所述。实现很简单:

void onMutation(Node node, void listener(MutationObserver obs)) {
  final observer = new MutationObserver(() {
    listener(observer);
    observer.disconnect();
  })..observe(node, childList: true, subtree: true);
}

因此,对于您的特定示例,粘贴 onMutation 函数,然后像这样编写:

var id1 = query("#id1");
id1.model = xxxx
onMutation(id1.parent, (_) {
    var id2 = query("#id2");
    id2.model = xxxxx;
    onMutation(id2.parent, (_) {
      print(query(xxx));
    });
});

关于html - 在 Dart 中如何查询嵌套模板中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18908009/

相关文章:

javascript - 使用 JQuery 从 HTML 表中提取数据

jquery - 隐藏和显示 div onclick svg

html - 在网络应用程序谷歌应用程序脚本上渲染部分谷歌电子表格

javascript - 如何在函数中正确访问 DOM?

ios - 如何在调用另一个方法之前等待 didUpdateLocation 方法被调用?

javascript - 如何争论 Node.JS 异步

javascript - 通过菜单按钮滚动时 JavaScript 出现问题

java - 在java中的XML中设置属性/节点

javascript - 在 extjs 中为 DOM 操作分配 tpl 值

c# - SemaphoreSlim 在极端条件下无法工作?