嘿,我对 Handlebars.js 完全陌生,对 JavaScript 本身也几乎陌生。所以我尝试通过以下 tut:http ://coenraets.org/blog/phonegap-tutorial/
我完成了第 5 部分并想在浏览器中测试应用程序。但是页面是空白的。浏览器会自己识别handlebars.js并自动渲染handlebars模板吗?或者为什么我会收到一个空白页?
我希望这些问题不是基本的,但是我不知道如何进行或我的错误在哪里。索引.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>
主.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();
我在 main.js 中得到以下错误:ln。15: 未捕获的 ReferenceError: Handlebars 未定义 ln 20。:Uncaught TypeError: Object # has no method 'homeTpl'
亲切的问候,斯纳夫