Backbone layoutmanager嵌套视图错误

时间:2013-06-04 17:55:14

标签: backbone.js nested views backbone-layout-manager

尝试在Backbone layouamanager中使用嵌套视图时,我遇到了一个奇怪的错误。这是嵌套视图(我也使用RequireJS):

define([
'jquery',
'underscore',
'backbone',
'templates',
], function ($, _, Backbone, JST) {
'use strict';

var ResultsView = Backbone.View.extend({
    template: JST['app/scripts/templates/results.ejs'],

});

return ResultsView;
});

这是父布局视图:

define([
'jquery',
'underscore',
'backbone',
'templates',
'layoutmanager',
'views/results-view'
], function ($, _, Backbone, JST, manager, ResultsView) {
'use strict';

Backbone.Layout.configure({
  manage: true
}); 

var AppView = Backbone.Layout.extend({
    template: JST['app/scripts/templates/App.ejs'],
    el: '#container',

    views: {
        "#search-results": new ResultsView()
    }
    });

  return AppView;
});

以下是实例化父布局的代码:

define([
'jquery',     
'underscore',
'backbone',
'views/App-view'
 ], function($, _, Backbone, AppView){

var initialize = function(){
    new AppView().render(); 
};

return {
   initialize: initialize
  };

});

当我加载页面时,我收到以下错误:

"Uncaught TypeError: Cannot read property 'ownerDocument' of undefined"

错误来自Jquery。如果我从上面的代码中删除了这一行:

el: '#container',

错误消失了。我还是Backbone的新手,所以也许我错误地使用了这个视图?谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

我把它作为我的HTML:

<div class="container"></div>

而在我的骨干视图中,我使用的是这样的:

el: "#container"

因为它是一个id选择器和我的html使用类,所以骨干网永远找不到dom元素。将html更改为具有“容器”的ID修复它

相关问题