我在 ICanHaz.js 文档上读到我应该像这样从远程加载模板
$.getJSON('/myserver/templates.json', function (templates) {
$.each(templates, function (template) {
ich.addTemplate(template.name, template.template);
});
});
我不知道 json 模板应该是什么样子,非常感谢 ICanHaz.js json 模板示例。
谢谢
最佳答案
为了节省调试时间 $.each 需要回调函数的两个参数:迭代器和实际对象
$.getJSON('/myserver/templates.json', function (templates) {
$.each(templates, function (id, template) {
ich.addTemplate(template.name, template.template);
});
});
当然你一定要记得设置promise,因为这些模板都是异步加载的。
关于javascript - 如何使用 node.js 加载 ICanHaz.js 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8682434/