且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

推荐用于 JQuery 的 JavaScript HTML 模板库?

更新时间:2023-02-25 13:30:27

坦率地说,客户端模板现在很火,但也很复杂.

Well, to be frank, client-side templating is very hot nowadays, but quite a jungle.

我相信最受欢迎的是:

  • pure:只使用js,不使用他自己的语法"
  • mustache:相当稳定和不错的我听到了.
  • jqote2:极快根据jsperfs
  • jquery 模板(已弃用):
  • 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.