JavaScript模板框架 [英] Javascript template framework

查看:69
本文介绍了JavaScript模板框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写许多Web应用程序,这些应用程序需要大量动态内容,这些动态内容会根据对PHP + mySQL后端的各种ajax请求进行替换,从而能够将所有数据作为JSON响应.这可能是测验,民意测验,也可能是需要更多DOM更新的更高级的应用程序. 关键是与HTML的集成(由第三部分编码)非常容易.

I am writing a lot of web applications that requires a lot of dynamic content that is replaced according to various ajax request to the PHP+mySQL backend that is able to respond all data as JSON. This could be something like quizzes, polls or it could also be more advanced applications that requires more updates of the DOM. The point is that the integration with the HTML (wich is coded by a third part) is as easy as possible.

由于这是许多小型应用程序,而不是大型站点,因此,我正在寻找一个可以帮助我快速,轻松地完成工作的库,以便以后进行自定义. 我不知道执行此操作的最佳方法,但是我知道有各种各样的库可以满足我的需求(还有更多).

Since this are many small applications and not a big site, I am looking for a library that helps me get the job done fast and easy to customize later on. I don't know the best way of doing this but know that there are various libraries out there that does what I need (and a lot more).

必需功能:

  • 轻巧
  • 易于更新HTML结构(即使对于仅HTML编码人员也是如此)
  • 与jQuery兼容
  • 可与所有现代浏览器一起使用,包括Chrome,Firefox,Safari和IE7 +
  • 可与所有移动浏览器一起使用,包括Android,iOS和Windows Mobile

推荐答案

小胡子非常扎实,但是我发现它对无逻辑模板"问题有点强硬.例如,它没有提供您希望在模板系统中提供的许多小细节,例如"else"语句.您必须一直这样做愚蠢的事情:

Mustache is pretty solid, but I found it to be a little too hardline about the "logicless template" thing. For example, it doesn't offer a lot of small niceties you'd hope for in a templating system, like an "else" statement. You have to do dumb stuff like this all the time:

{{#if foo}}
    <span>foo is set</span>
{{/if}
{{^if foo}}
    <span>foo is not set</span>
{{/if}}

相反,我建议车把,该车建立在Mustache的顶部,但添加了一些不错的功能,例如自定义助手以及更好的上下文切换支持.

Instead, I'd recommend Handlebars which is built on top of Mustache, but adds some nice features like custom helpers and better context-switching support.

这篇关于JavaScript模板框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆