从手柄调用Javascript函数 [英] Calling Javascript function from handlebar
本文介绍了从手柄调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从句柄脚本内部调用Javascript函数?
原因:
我无法从里面破解 {{#each}}
车把。所以我需要将它传递给Javascript来完成逻辑。
解决方案
您可以使用助手来完成此操作;
Handlebars.registerHelper(printItems,function(items){
var html =< ul>;
items.forEach(function(entry){
html + =< li> + entry +< / li>;
});
html + =< / ul>;
返回html;
});
和您的句柄模板中;
{{printItems items}}
在列表中。
有关更多详情,请参阅此处。转到助手部分
How can I call a Javascript function from inside a handlebar script ? Reason:
I wasn't able to break the {{#each}}
from inside handlebars. So I need to pass it to Javascript to do the logic.
解决方案
You can do that with helpers;
Handlebars.registerHelper("printItems", function(items) {
var html = "<ul>";
items.forEach(function(entry) {
html += "<li>" + entry + "</li>";
});
html += "</ul>";
return html;
});
and in your handlebars template;
{{printItems items}}
Above code will put your items in list.
For more details refer here. Go to helpers section
这篇关于从手柄调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文