作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试抽象一些代码,并想利用dust.helpers来渲染部分。
我当前的设置:
{> "includes/components/link" /}
我的理想设置:
{@uiComponent name="link" /}
我的 helper :
dust.helpers.uiComponent = function (chunk, context, bodies, params) {
return dust.render('includes/components/' + name, context, function (err, out) {
chunk.end(out);
});
};
我还尝试了许多其他方法,但没有任何效果。
是的,我尝试查看文档。 :(
如有任何建议,我们将不胜感激!
最佳答案
在 Dust 中,助手会返回 Chunk,因此您需要使用 Chunk 方法从助手中返回,而不是 dust.render
。
在本例中,您正在使用部分,因此您需要 chunk.partial
:
dust.helpers.uiComponent = function (chunk, context, bodies, params) {
var name = context.resolve(params.name);
return chunk.partial('includes/components/' + name, context, params);
};
关于javascript - 灰尘JS : Render partial via a Helper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32013937/
我喜欢 this template library 的语法对于 JS。我将在 Node.js 脚本中使用它,因此性能非常重要。有人试过这个吗? (他们的网站运行速度太慢,以至于我认为他们的图书馆运行速
{?}之间究竟有什么区别?和 {#} ? —— 经过一点测试,列出所有truthy/falsy values for {?} ,并将它们与 {#} 进行比较: 上下文 : { values: [
寻找有关从dust.js模板助手发出异步请求的一些想法和反馈: Dust.js 可以从模板助手发出异步请求,但使用它们实际上是一个好主意吗?考虑这种情况... 特定页面需要呈现多个 api 请求。在页
我是一名优秀的程序员,十分优秀!