Reputation: 271
Hey I am completly new to Handlebars.js and almost new to JavaScript itself. So I tried to go through the following tut: http://coenraets.org/blog/phonegap-tutorial/
I completed Part 5 and wanted to test the app in the browser. But the page ist blank. Does the browser recognize handlebars.js by himself and renders the handlebars template automatically? Or why do I receive a blank page?
I hope the questions is not to basic, however I have no clue how to proceed or where my error lies. index.html:
<html>
<body>
<script id="home-tpl" type="text/x-handlebars-template">
<div class='header'><h1>Home</h1></div>
<div class='search-bar'><input class='search-key' type="text"/></div>
<ul class='employee-list'></ul>
</script>
<script id="employee-li-tpl" type="text/x-handlebars-template">
{{#.}}
<li><a href="#employees/{{this.id}}">{{this.firstName}} {{this.lastName}}<br/>{{this.title}}</a></li>
{{/.}}
</script>
<script src="lib/jquery-1.8.2.min.js"></script>
<script src="js/storage/memory-store.js"></script>
<script src="js/main.js"></script>
<script src="lib/handlebars.js"></script>
</body>
main.js:
var app = {
findByName: function() {
var self = this;
this.store.findByName($('.search-key').val(), function(employees) {
$('.employee-list').html(self.employeeLiTpl(employees));
});
},
initialize: function() {
var self = this;
this.store = new MemoryStore(function() {
self.renderHomeView();
});
this.homeTpl = Handlebars.compile($("#home-tpl").html());
this.employeeLiTpl = Handlebars.compile($("#employee-li-tpl").html());
},
renderHomeView: function() {
$('body').html(this.homeTpl());
$('.search-key').on('keyup', $.proxy(this.findByName, this));
},
showAlert: function (message, title) {
if (navigator.notification) {
navigator.notification.alert(message, null, title, 'OK');
} else {
alert(title ? (title + ": " + message) : message);
}
},
};
app.initialize();
I get the follwoing errors in main.js: ln. 15: Uncaught ReferenceError: Handlebars is not defined ln 20. :Uncaught TypeError: Object # has no method 'homeTpl'
Kind regards, Snafu
Upvotes: 0
Views: 8822
Reputation: 9
I did the above change...which seemed quite logical. However, the above solution didn't work.
I added the below
this.homeTpl = Handlebars.compile($("#home-tpl").html());
this.employeeLiTpl = Handlebars.compile($("#employee-li-tpl").html());
in the renderHomeView function... Works well for me..... :)
renderHomeView: function() {
this.homeTpl = Handlebars.compile($("#home-tpl").html());
this.employeeLiTpl = Handlebars.compile($("#employee-li-tpl").html());
$('body').html ( this.homeTpl());
$('.search-key').on('keyup', $.proxy(this.findByName, this));
}
Upvotes: 0