07002:
Pros: Seems to follow Backbone’s idea of separation on concerns which helps keep your templates very “clean”.
Cons: Looks like you have to write a bit more code in your views to define bindings. Also,seems to lack the ability to do conditional rendering so you have to always render the full template and just toggle the display of certain elements.
Pros: Handles a bit more data binding options within the template without making it too messy.
Cons: Also,seems to lack conditional rendering.
Pros: Handles all kinds of data binding needs through attributes.
Cons: Easy to start “dirtying” the template with converters. Have to add another step to create Knockout view-models from Backbone models.
Pros: Similar to Knockout’s abilities but with different Syntax. Handles conditional rendering.
Cons: In the past we dirtied our templates by adding too much business logic within the template but that may be an issue with our development that we can correct. Need to create functionality to tie JsViews observability functionality to Backbone model events. Other libraries like StickIt and Knockback automatically handle this.
我们还研究了Backbone.ModelBinder,这是StickIt和Rivets之间的某个地方.
解决方法
Mustache.js
Pro的:不仅胡子支持变量绑定,而且还可以处理函数绑定.例如你可以拥有
<a href="{{test}}" >click me </a>
然后在你看来有一个叫做test的方法.这节省了大量的rendundant分配类/ id链接,并在View类中绑定事件.
Con的:我不喜欢它的语法.
接下来,我在Ruby on Rails中使用了coffeescript,它在jst eco模板系统中有一个构建.一个亲,你有分开的文件模板.在pageload中,它们绑定到dom中的全局变量.这些被缩小,并且比一些伪脚本模板标签更好.另一个亲,你写如果else和for循环像你这样在ruby.不利的是,他们使用剃刀标签,并且不允许容易地与服务器端代码(如翻译)混合.
其他图书馆则是强调模板引擎.很简单,但相当强大.预测,您已经可以使用(骨干网需要下划线).缺点是,您无法(默认情况下)从外部文件加载模板.我已经通过使用serverside代码(require_once,render partial)来解决这个问题.如果您使用require.js,连同文本插件(http://requirejs.org/docs/download.html#text),您可以加载模板作为依赖.