我如何加载ICanHaz.js模板与node.js?

我读了ICanHaz.js文档,我应该像这样从远程加载模板

$.getJSON('/myserver/templates.json', function (templates) { $.each(templates, function (template) { ich.addTemplate(template.name, template.template); }); }); 

我不知道json模板应该是什么样子,真的很感谢一个ICanHaz.js json模板的例子。

谢谢

为了节省一些时间在debugging$ .each需要两个参数的callback函数:迭代器和实际的对象

 $.getJSON('/myserver/templates.json', function (templates) { $.each(templates, function (id, template) { ich.addTemplate(template.name, template.template); }); }); 

当然,您必须记得设置承诺,因为这些模板是以asynchronous模式加载的。

Interesting Posts