0

尝试在 Backbone layoamanager 中使用嵌套视图时遇到一个奇怪的错误。这是嵌套视图(我也在使用 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 的新手,所以也许我错误地使用了视图?谢谢你的帮助

4

1 回答 1

0

我有这个作为我的html:

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

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

el: "#container"

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

于 2013-06-05T16:35:36.683 回答