使用backbone.marionette的外部模板

时间:2012-06-10 10:29:09

标签: backbone.js backbone-views marionette

使用Backbone.View我以这种方式获取外部模板(1)

如果我想使用Backbone.Marionette.Layout从外部文件获取模板怎么办? (2)


(1)

define(['myTemplate.html'], function (myTemplate) {
    var MyView = Backbone.View.extend({
        render: function ()
        {
            this.$el.html(myTemplate, this.getView());
        }
    });

    return MyView;
});

(2)

define(['myTemplate.html'], function (myTemplate) {
    var Layout = Backbone.Marionette.Layout.extend({

        template: "#container",

        regions: {
            top: "#top",
            main: "#main"
        }
    });

    return Layout;
});

1 个答案:

答案 0 :(得分:2)

看看这个:https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs

this.$el.html(myTemplate, this.getView());