Context Is Not Defined Javascript
So referring to the original problem I have here Google Maps Javascript V3 Uncaught TypeError: Cannot read property 'offsetWidth' of null and after doing a lot of googling, I have
Solution 1:
In this line:
$("employee-tpl").append(HTMLtemplate(context))
You are passing an undefined
function and one undefined
variable (context
).
context
should contain he id
parameter you defined in your HandlebarJS template to be replaced
<ahref="#map/{{this.id}}">See on map</a>
HTMLTemplate
in your case is EmployeeView.template
which holds the HandlebarJS compiled template: it is a function that receives as arguments the context
variable ( or maybe the employee
variable?)
If I got it right your code should be:
varEmployeeView = function(employee){
this.render = function(){
$('body').append(this.el);
// inside the new div, put the Handlebars template, with the data from the employeethis.el.html(EmployeeView.template(employee))).ready( function() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
});
returnthis;
};
this.initialize = function(){
this.el=.$("</div>");
window.localStorage.removeItem('paramId');
console.log('removed');
window.localStorage.setItem('paramId',employee);
console.log('added ' + employee.id);
};
this.initialize();
}
EmployeeView.template = Handlebars.compile($("#employee-tpl").html());
I think you have to pass employee
to the template because I saw first_name
and last_name
in the template.
Post a Comment for "Context Is Not Defined Javascript"