backbone.js – 使用backbone.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;
});

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

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