Here is my view:
define([
'jquery',
'underscore',
'backbone',
'models/tableModel',
'collections/tablesCollection',
'views/tablesView'
], function($, _, Backbone, tableModel, tablesCollection, tablesView) {
require(['collections/tablesCollection'], function(tablesCollection) {
var t = new tablesCollection(null, {url: 'main-contact'});
var tables = new tablesView({ collection: t, template: 'main-contact-template'});
tables.url = 'main-contact';
return tables; // <!-- returns view, tables can be console.log'ed
});
console.log(tables); // <!-- tables is not defined
});
How do I get the tables within the require statement so that is accessible where the console.log is? This seems to be where I need to return the view from, so I can use it in my route:
app_router.on('route:index', function(){
require(['views/tables/mainContactView'], function(mainContactView) {
console.log(mainContactView); // <!-- undefined, unless some value is returned from where the console.log() is above
$('#web-leads').html(mainContactView.render().el);
});
});
If I put return 'test' where the console.log(tables) is, I can console.log() it in my route. So I assume that’s where I need to return the view from. How do I pass that data out? Right now, even with a return statement, my view is undefined. I need to get the view out of the require. How do I do that?
You’ve already loaded
collection/tablesCollectionin define, so you don’t have to do anotherrequireto get it loaded.You can simply the definition of the View as this: