【发布时间】:2017-02-15 14:39:14
【问题描述】:
我正在使用Aurelia。
我有一个post 路由,它会根据传递的id 显示一个帖子。
服务器编译用于将帖子写入 HTML 的 Markdown,我正在使用以下方法在模板中加载此内容:
<div innerHTML.bind="post.content"></div>
// in the activate() function
client
.fetch(`api/post/${params.id}`)
.then(res => res.json())
.then(data => {
this.post = data;
// this is the workaround I am currently using
setTimeout(this.displayLineNumbers, 200);
});
当内容已附加到视图时,我找不到任何方法来执行函数。 如果我只使用:
this.post = data;
this.displayLineNumbers();
它将失败,因为内容尚未附加,因此我的功能要更改的元素尚不可用。我目前使用的解决方法是等待 200 毫秒,然后执行该函数。
有什么方法(事件或函数)可以知道何时附加了动态加载的内容?或者可能是 innerHTML.bind 之外的另一种内容模板方式?
【问题讨论】:
标签: javascript aurelia aurelia-templating