Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates Dart:等待模板完成_Templates_Dart_Dart Polymer - Fatal编程技术网

Templates Dart:等待模板完成

Templates Dart:等待模板完成,templates,dart,dart-polymer,Templates,Dart,Dart Polymer,我有一个HTML,其中包含一些模板,还有一个函数可以更改绑定的模板。 函数如下所示: void onHover(事件e、变量详细信息、节点发送方){ this.querySelector('#testobind').setAttribute(“ref”,“Btn2”); this.querySelector('#Btn2').onMouseLeave.listen((e){ this.querySelector('#testobind').setAttribute(“ref”,“Btn1”);

我有一个HTML,其中包含一些模板,还有一个函数可以更改绑定的模板。 函数如下所示:

void onHover(事件e、变量详细信息、节点发送方){
this.querySelector('#testobind').setAttribute(“ref”,“Btn2”);
this.querySelector('#Btn2').onMouseLeave.listen((e){
this.querySelector('#testobind').setAttribute(“ref”,“Btn1”);
}
当鼠标进入Btn1时,Btn2应该显示,如果鼠标离开Btn2,Btn1应该再次显示。如果我查询Btn2总是
null
,我猜是因为模板尚未完成加载。 当模板加载完成时,有没有办法获得回调

模板如下所示:


1.
2.

据我所知,没有事件,但通常通过
新未来(()=>…)
调度微任务来延迟执行

void onHover(事件e、变量详细信息、节点发送方){
this.querySelector('#testobind').setAttribute(“ref”,“Btn2”);
调度微任务(){
this.querySelector('#Btn2').onMouseLeave.listen((e){
this.querySelector('#testobind').setAttribute(“ref”,“Btn1”);
});
}
void onHover(事件e、变量详细信息、节点发送方){
this.querySelector('#testobind').setAttribute(“ref”,“Btn2”);
新未来(){
this.querySelector('#Btn2').onMouseLeave.listen((e){
this.querySelector('#testobind').setAttribute(“ref”,“Btn1”);
});
}

代码下面的文本似乎缺少一些“…如果我查询Btn2总是???,我猜…”它是空的。我更正了它。设置属性
ref
时发生的情况也不明显。如何实现显示/隐藏按钮?能否添加包含模板标记的HTML?两个模板都包含一个Div,其中包含一个按钮。您使用的是聚合元素还是自动绑定dart元素,或者您使用的是什么类型的模板?我在HTML中找不到任何与
“#atterobind”
匹配的内容。尝试使用scheduleMicrotask:
scheduleMicrotask(()=>this.querySelector('#atterobind').setAttribute(“ref”,“Btn2”));this.querySelector('#Btn2').onMouseLeave.listen((e){this.querySelector('#testobind').setAttribute(“ref”,“Btn1”);
它仍然是空的,但我不确定我是否做得正确,因为我没有用async做太多。我不是100%确定
scheduleMicrotask
但用
Future
它的工作原理与我更新的答案中所示的一样。Future确实起作用。scheduleMicrotask它仍然
null
new Future()
是否实际延迟查询,直到模板过期?
newfuture()
不关心或不知道模板,传递给
未来的
的闭包将在事件队列中排队,并在完成所有其他先前计划的任务时执行。如果更改模板,这会将一个任务排队,然后再将另一个任务排队。这是解决此问题的简单而有效的方法。
scheduleMicrotask
更细粒度,可能会在其他排队任务之前执行。请参阅此处的更多详细信息