Very sorry, I gave you a function but it was really inside a class. Here is all of it. It isn't really a promise. They didn't have that in 2013 I don't think. I left off the place about caching but I did put in the part about var debug = false but maybe I want debugging on since that didn't solve the problem. Yes it is old code with global variables but I just want it to load the view. It is a Backbone.js solution with Jquery. The part it is sticking on is below this code. This is the code that loads the handlebars template. It's on document load from the index page.
var promises = {};
var TemplateManager = (function(){
// dev location
var _template_dir = 'javascripts/templates/',
// Cache the returned deferred/promise by the id of the template
// so that we can prevent multiple requests for the same template
// from making the ajax call.
//
// This code is only safe to run synchronously. There exists a
// race condition in this function, when run asynchronously,
// which would nullify the benefit under certain circumstances.
_loadTemplateAsync = function(tmpId, type){
var promise = '', ext = '.js';
if(type == 'html') {
ext = '.html';
}
else if(type == 'js') {
ext = '.js';
}
promise = promises[tmpId] || $.get(_template_dir + tmpId + ext).error(function () {
if(var debug = false && window.console) {
console.log('Cannot load the ' + tmpId + ' view.');
}
});
promises[tmpId] = promise;
return promise;
};
return {
// Use jQuery to asynchronously load the template.
loadTemplate : function(templateId, templateType, callback){
var tmpId = templateId.replace("#", "");
var promise = _loadTemplateAsync(tmpId, templateType);
promise.done(function(template){
callback.call(this, $(template));
});
}
};
})();
------------
This is where the error occurs in the debugger .
promise = promises[tmpId] || $.get(_template_dir + tmpId + ext).error(function () {
if(debug && window.console) {
console.log('Cannot load the ' + tmpId + ' view.'); ********
}
});
promises[tmpId] = promise;
return promise;
};
----
This is the jquery in the index.html
jQuery(document).ready(function () {
app = new Auto.App();
Backbone.history.start();
});
--------
This is the backbone app:
Auto.App = Backbone.Router.extend({
routes : {
"" : "showDashboardMain",
"myprofile" : "showEditProfile"
},
/*
* view object
*/
dashboardView : {},
signinView : {},
initialize : function () {
this.dashboardView = new Auto.View.Dashboard({
"collection" : AutoDashboard
});
},
/**
* show the user edit profile
*/
showEditProfile : function () {
this.dashboardView.renderUserAccountView();
},
showDashboardMain : function () {
this.dashboardView.renderDashboardView(); *************stops here cannot show user profile
// show the user profile
}
});
I wish I knew how to debug it. The Auto.app creates the dashboard but it stops at the route I guess for the user profile? Soemthing like that.