16

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.

4

4 に答える 4

24

マリオネットでハンドルバーを使用する簡単な方法はtemplate、各ビューでコンパイル済みのハンドルバー テンプレート関数として定義することです。例えば:

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

Marionette のデフォルトRendererでは、属性が関数であることを検出し、templateそれに応じて呼び出します。

このケースに関する公式ドキュメントも参照してください: https://github.com/marionettejs/backbone.marionette/wiki/Using-handlebars-templates-with-marionette

および requirejs + Marionette + Handlebars precompiled を使用したその他の Q/A : Using precompiled handlebars templates with Marionette

于 2013-04-02T19:13:40.443 に答える
6

@brettjonesdevは正しいですが、ここでうまく機能したもう1つの追加は次のとおりです。

var MyView = Backbone.Marionette.ItemView.extend({
  template: Handlebars.compile($("#assign-products-main-view").html()),
  model: new Backbone.Model({name: "Steve"})
});

これは、DOM を検索するときに役立ちます。

于 2013-07-10T06:28:18.667 に答える
2

現在の 2 つの回答は、キャッシュを利用していません。代わりにこの要点を使用してください。

于 2014-06-12T04:29:07.810 に答える