我有一个页面,它使用木偶布局将视图绑定到#content。
我的应用程序中的登陆页面是许多视图一起绘制的,所以我计划使用另一个布局视图,而不是一个复合视图。
但是,现在使用下面的代码,我得到:
TypeError: object is not a function 我的controller.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;
})任何帮助都非常感谢
发布于 2013-09-12 20:16:59
看起来,您正在从索引中返回一个新的layout对象,然后尝试将其用作控制器中的函数。
在你的索引中:
layout = new AppLayout();
...
return layout;然后在你的控制器里:
return MyApp.content.show(new View());你可能只需要做
return MyApp.content.show(View);在更新之后,我们发现了另一个问题。呈现视图的顺序是错误的。语句layout.collection1.show(new ImagesView());实际上不会呈现任何内容,因为layout本身还没有呈现。解决这个问题的方法是将该语句移到AppLayout的AppLayout方法中。这样,当调用MyApp.content.show(View)时,它将在正确的时间自动呈现ImagesView。
https://stackoverflow.com/questions/18768424
复制相似问题