In building a view to control re-usable ui controls (tabs, modals, alerts, etc). I want to be able to call ui.tabs(options)
which will then create the view 'object'.
I've managed to get so far that I can call ui.tabs(options)
. But now I can't quite figure out how to set the element with a views method (ie: tabs()
). When I set a template to this.el
, this.$el
or this.$el.html
I just get an undefined error.
Can someone explain where i'm going wrong?
Here's my code so far (simple I know):
/* UI Tools */
define(
[
"backbone",
"text!templates/ui-tabs.html"
],
function (Backbone, tabsTemplate) {
var uiView = Backbone.View.extend({
events: {
"click .tab": "clickTab"
},
initalize: function () {
},
/*
* TAB CONTROLS
*/
tabs: function (options) {
console.log(options);
console.log(this.$el);
this.el = $(_.template(tabsTemplate, options));
},
clickTab: function () {
console.log('tab clicked');
},
/*
* MODAL CONTROLS
*/
modal: function () {
},
/*
* ALERT CONTROLS
*/
alert: function () {
},
/*
* CORE
*/
render: function () {
return this.$el;
}
});
return new uiView();
}
);