推荐用于 JQuery 的 JavaScript HTML 模板库?
关于哪个 HTML 模板库适合 JQuery 的任何建议?谷歌搜索找到了相当多的库,但我不确定是否有一个公认的经得起时间考验的库.
Any suggestions on which HTML template library would go well with JQuery? Googling turns up quite a number of libraries but I'm not sure whether there is a well recognized library that would stand the test of time.
坦率地说,客户端模板现在很火,但也很复杂.
Well, to be frank, client-side templating is very hot nowadays, but quite a jungle.
我相信最受欢迎的是:
- pure: It use only js, not his own "syntax"
- mustache: quite stable and nice I heard.
- jqote2: extremely fast according to jsperfs
- jquery templates (deprecated):
还有很多其他的,但您必须对其进行测试,以了解什么最适合您,以及最适合您的项目风格.
there are plenty others, but you have to test them to see what suits you, and your project style, best.
就我个人而言,我很难添加新的语法和逻辑集(混合逻辑和模板,你好??),然后转向纯 js.我的每一个模板都存储在它自己的 html 文件 (./usersTable.row.html) 中.我只在对内容进行 ajaxing 时使用模板,而且我的逻辑"js 文件很少,一个用于表格,一个用于 div,一个用于列表.甚至没有一个用于选择的选项(我使用另一种方法).
Personally, I have a hard time with adding a new syntax and set of logic (mixing logic and template, hello??), and went pure js. Every single one of my templates is stored in it's own html file (./usersTable.row.html). I use templates only when ajaxing content, and I have few "logic" js files, one for tables, one for div, one for lists. and not even one for select's options (where i use another method).
每次我尝试做一些更复杂的事情时,我都会发现代码不太清晰,而且与旧"方式相比,我花了更多的时间来稳定.在我看来,模板中的逻辑完全是无稽之谈,添加它自己的语法只会增加非常难以追踪的错误.
Each time I tried to do something more complex, I found out the code was less clear and taking me more time to stabilize than doing it the "old" way. Logic in the template is an utter non-sense in my opinion, and adding it's own syntax adds only very-hard-to-trace bugs.