Mustache.js完成渲染模板后如何运行回调 [英] How to run a callback when Mustache.js has finished rendering template

查看:247
本文介绍了Mustache.js完成渲染模板后如何运行回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦Mustache.js完成呈现模板并将其插入到DOM中,是否有一种干净的方法来定义/运行回调函数?例如,如下所示:

Is there a clean way to define/run a callback function once Mustache.js has finished rendering a template and inserting it into the DOM? For example, something like this:

Mustache.render(template, viewModel, function() {...});

我能想到的最好的办法是计算将要插入DOM的视图模型中的节点数,然后使用setInterval来检查DOM中是否存在许多节点.一旦完成,我就可以调用我想要的函数.对我来说,这似乎效率低下,而且可能有问题,但我不知道该怎么办.

The best I've been able to come up with is counting the number of nodes in my view model that will be inserted into the DOM, and then using setInterval to check if that many nodes exist in the DOM. Once they do, I can then call the function I want. This seems inefficient and potentially buggy to me, but I don't know what else to do.

推荐答案

与胡须无关,实际上与jQuery .html()有关.

Not related to mustache, actually it is about jQuery .html().

$('.your_div').html(rendered).promise().done(function(){

$('.your_div').html(rendered).promise().done(function() {

// do your stuff

});

这篇关于Mustache.js完成渲染模板后如何运行回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆