我们正在使用 Marionette.js,并希望我们可以根据窗口的大小来切换布局的活动模板。但是,该getTemplate()
函数似乎只在视图加载时调用一次。
在 Marionette 中加载布局后,有没有办法切换当前模板?我们有这个代码:
initialize: function() {
//... other code
this.windowWidth = 0;
$(window).resize(this.resizeHandler);
},
getTemplate: function () {
if (this.windowWidth <= 1050) {
return "#small-screen-template";
}
return "#large-screen-template";
},
resizeHandler: function () {
this.windowWidth = $(window).width();
}