我已经编写了dust js,我从 jquery 本地函数调用渲染函数。
请举例说明灰尘渲染如何恢复。是否需要调用onload函数?
dust.render("tmp_skill", json_object, function(err, html_out) {
//HTML output
$('#page').html(html_out);
console.log(html_out);
});
最佳答案
你的代码没问题,你可以随时调用render方法。如果你在onload中调用它,你必须事先在dust缓存中编译并加载该模板(tmp_skill)。
渲染灰尘的步骤是:
1) 编译模板 2)将其加载到具有名称的dust缓存中。 3)渲染模板
所以
var compiled = dust.compile("Hello world {name}", "tmp_skill");
dust.loadSource(compiled);
dust.render("tmp_skill", json_object, function(err, html_out) {
//HTML output
$('#page').html(html_out);
console.log(html_out);
});
您需要的任何内容都可以阅读我们的维基。您会在这里找到很多文档和示例:https://github.com/linkedin/dustjs/wiki
关于dust.js - dust.render 何时以及如何接到电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11934726/