使用Handlebars.js与Backbone.Marionette [英] Use Handlebars.js with Backbone.Marionette

查看:108
本文介绍了使用Handlebars.js与Backbone.Marionette的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用Handlebars.js与 Backbone.Marionette 扩展程序,而不重新实现视图渲染功能?看来,木偶是依靠您使用Backbone.js的下划线模板引擎的惯例。但我真的很喜欢在车把的做法,所以我问如果我能木偶与车把高层次的工具。

Is it possible to use the Handlebars.js with the Backbone.Marionette extension without reimplementing the Views render function? It seems that Marionette is relying on the convention that you use Backbone.js with underscores templating engine. But I really like the handlebar approach so I'm asking if I can the high-level-tools of Marionette with handlebars.

推荐答案

使用与木偶车把一个简单的方法是简单地定义模板中的每个View为pre-编译把手模板函数。例如:

A simple way to use Handlebars with Marionette is simply to define template in each View as a pre-compiled Handlebars template function. For instance:

var MyView = Backbone.Marionette.ItemView.extend({
    template: Handlebars.compile("Hello, {{name}}"),
    model: new Backbone.Model({name: "Steve"})
});

木偶的默认渲染将检测到模板属性是一个函数,并相应地调用它。

Marionette's default Renderer will detect that the template attribute is a function, and will call it accordingly.

另请参见有关这个案子的官方文档:<一href=\"https://github.com/marionettejs/backbone.marionette/wiki/Using-handlebars-templates-with-marionette\">https://github.com/marionettejs/backbone.marionette/wiki/Using-handlebars-templates-with-marionette

See also the official documentation about this case : https://github.com/marionettejs/backbone.marionette/wiki/Using-handlebars-templates-with-marionette

和与requirejs +木偶+把手precompiled的其它Q / A:<一href=\"http://stackoverflow.com/questions/19863285/using-$p$pcompiled-handlebars-templates-with-marionette\">Using与木偶 precompiled车把模板

and an other Q/A with requirejs + Marionette + Handlebars precompiled : Using precompiled handlebars templates with Marionette

这篇关于使用Handlebars.js与Backbone.Marionette的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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