Backbone Layout Manager - Property 'parent' of undefined

517 views Asked by At

I've been following the example code shown here.

Here I'm simply trying to return a layout manager view.

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

        return Backbone.Layout.extend({
            template: '#main-layout'
        });
});

Here, I'm instantiating a new view called myView. It's being loaded using requirejs.

require(['app', 'jquery', 'myView'], function (app, $, myView) {
    'use strict';
    var myView = new myView();
    myView.$el.appendTo(".container");
    myView.render();
});

Rendering the view causes the following error to pop up in the console:

Uncaught TypeError: Cannot read property 'parent' of undefined
1

There are 1 answers

3
Patrick Gunderson On BEST ANSWER

Instead of myView.$el.appendTo(".container"); you should insert the view into a parent view:

var myView = new myView();
var container = Layout.getView('.container');
container.insertView(myView);
myView.render();