I am familiar with building backbone apps but am trying to convert it to use requirejs, the issue i am facing is when i am trying to extend the parent view, it is undefined
when trying to extend base-view.js to properties-view.js
define(['backbone','underscore','jquery','views/node/base-view'],
function(Backbone, _, $, NodeBaseView){
PropertiesView = NodeBaseView.extend({
});
}
});
Instantiating a child view inside the parent base view
define(['backbone','underscore','jquery','views/node/properites-view'], function(Backbone, _, $, PropertiesView){
NodeBaseView = Backbone.View.extend({
..
new PropertiesView({});
..
});
});
Here NodeBaseView is undefined
when trying to extend it for PropertiesView. Any Help?
Note: I am using AMD versions of backbone and underscore from here https://github.com/amdjs
The problem here appears to be a circular dependency. Base view requires properties view, and vice versa. This results in one of them being undefined.
Let's pretend this definition sits in 'views/main'
define(['backbone', 'views/node/base'],
function(Backbone, BaseView){
var MainView = BaseView.extend({
});
return MainView;
}
);
Then as your child view:
define(['backbone', 'views/node/base'],
function(Backbone, BaseView) {
var PropertiesView = BaseView.extend({
});
return PropertiesView;
}
);
Then somewhere else in a universe far far away:
myView = new MainView();
Using the example from the manual:
define(['backbone', 'views/node/base'],
function(Backbone, BaseView){
var MainView = BaseView.extend({
});
return MainView;
}
);
Then
define(['backbone'], function (Backbone) {
var BaseView;
require(['views/node/base'], function(b){
BaseView = b;
});
var PropertiesView = BaseView.extend({
});
return PropertiesView;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With