Привет, я совершенно новый для Handlebars.js и почти новый для самого JavaScript. Поэтому я попытался проделать следующую работу: http://coenraets.org/blog/phonegap-tutorial/
Я завершил часть 5 и хотел протестировать приложение в браузере. Но страница ist blank. Распознает ли браузер handlebars.js самостоятельно и автоматически создает шаблон руля? Или почему я получаю пустую страницу?
Я надеюсь, что вопросы не в основном, но я не знаю, как действовать или где моя ошибка. 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();
Я получаю следующие ошибки в main.js: ln. 15: Uncaught ReferenceError: Handlebars не определен ln 20.: Uncaught TypeError: Object # не имеет метода 'homeTpl'
С уважением, Снафу
Двигайте handlebars.js
над вашим main.js
тегами сценария.
Я сделал вышеупомянутое изменение... которое казалось вполне логичным. Однако указанное выше решение не сработало.
Я добавил ниже
this.homeTpl = Handlebars.compile($("#home-tpl").html());
this.employeeLiTpl = Handlebars.compile($("#employee-li-tpl").html());
в функции renderHomeView... Хорошо работает для меня..... :)
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));
}