我有一个页面,使用木偶布局将视图绑定到#内容。
在我的应用程序中,我的登录页有很多视图,所以我计划使用另一个布局视图,而不是复合视图。
然而,目前与下面的代码我得到:
TypeError: object is not a function
我的控制器。js基于如下路由调用视图:
app.addRegions({
content: "#content"
});
define([], function() {
"use strict";
return {
landing: function() {
return require(["app/views/index"], function(View) {
return MyApp.content.show(new View()); ////LINE THROWING THE ERROR
});
}
};
});
导致问题的子布局
define([
"marionette",
'app/views/images/collection',
"tpl!app/templates/index.html"
],
function(Marionette, ImagesView, template) {
"use strict";
var AppLayout, layout;
AppLayout = void 0;
layout = void 0;
AppLayout = Backbone.Marionette.Layout.extend({
template: template(),
regions: {
collection1: "#images",
}
});
layout = new AppLayout();
layout.collection1.show(new ImagesView());
return layout;
})
非常感谢任何帮助
看起来像是从索引中返回一个新的布局
对象,然后尝试将其用作控制器中的函数。
在您的索引中:
layout = new AppLayout();
...
return layout;
然后在控制器中:
return MyApp.content.show(new View());
你可能只需要这样做
return MyApp.content.show(View);
更新在进行了更多的工作之后,我们发现了另一个问题。呈现视图的顺序是错误的。语句布局。收藏1。显示(新图像视图())代码>实际上不会渲染任何内容,因为
布局
本身尚未渲染。解决方法是将该语句移动到AppLayout
的onRender
方法中。这样,当MyApp时。所容纳之物调用show(View)
,它将在正确的时间自动呈现图像视图。