这是我的看法:
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
});
我如何tables
在require
声明中获取,以便在哪里可以访问console.log
?这似乎是我需要返回视图的地方,所以我可以在我的路线中使用它:
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);
});
});
如果我把它放在return 'test'
哪里console.log(tables)
,我可以console.log()
在我的路线上。所以我认为那是我需要返回视图的地方。我如何传递这些数据?现在,即使有一个 return 声明,我的观点也是不确定的。我需要从require
. 我怎么做?