引用错误:未定义车把
ReferenceError: Handlebars is not defined
我对Handlebars完全陌生.js对JavaScript本身几乎是新手。我在控制台上收到此错误"参考错误:未定义车把"。我已经尝试将所有引用放在"x车把模板"中,但它没有帮助。
index.tmpl.php:
<html>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type="text/css" href="style.css">
<title>PHP and jquery</title>
</head>
<body>
<div class="container">
<h1>Search films by title:</h1>
<form id="film-selection" action="index.php" method="post">
<select name="q" id="q">
<?php
$alphabet = str_split('abcdefghijklmnopqrstuvwxyz');
foreach ($alphabet as $letter) {
echo "<option value='$letter'>$letter</option>";
}
?>
</select>
<button type="submit">Go!</button>
</form>
<?php if(isset($film)): ?>
<ul class="film-list">
<?php
foreach ($film as $a) {
echo " <li data-film_id='{$a->film_id}'>
<a href='film.php?film_id={$a->film_id}'>{$a->title} </a>
</li>";
}
?>
</ul>
<?php endif; ?>
<script id="film_list_template" type="text/x-handlebares-templates">
{{#each this}}
<li data-film_id="{{film_id}}">
<a href="film.php?film_id={{film_id}}">{{fulName this}}</a>
</li>
{{/each}}
</script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/handlebars-v2.0.0.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</div>
</body>
</html>
脚本.js:
var Film = {
init: function(config){
this.config = config;
this.setupTemplates();
this.bindEvents();
},
bindEvents: function(){
this.config.letterSection.on('change', this.fetchFilm);
},
setupTemplates: function(){
//The error is in this line below.
this.config.filmListTemplate = Handlebars.compile(this.config.filmListTemplate); //here is the error
Handlebars.registerHelper('fulName', function(film){
return film.title;
});
},
fetchFilm: function(){
alert('Test2');
var self = Film;
$.ajax({
url: 'index.php',
type: 'POST',
data: self.config.form.serialize(),
dataType: 'json',
success: function(results){
//console.log(results[0].title);
self.config.filmList.append(self.config.filmListTemplate(results));
}
});
}
};
Film.init({
letterSection: $('#q'),
form: $('#film-selection'),
filmListTemplate: $('#film_list_template').html(),
filmList: $('ul.film-list')
});
我发现我的js目录中没有文件"handlebars-v2.0.0.js"。
相关文章:
- chrome.storage.sync未定义错误
- 对象为null或IE9中存在未定义错误
- 已定义变量出现未定义错误
- 'define' 在 RequireJS 和 Webapp Yo 生成器上未定义错误
- onreadystatechange未定义错误
- 在CoffeeScript文件上运行Jasmine测试时,对象未定义错误
- 如何修复JSlint报告的“foo未定义”错误
- 无法仅在活动服务器上读取未定义错误的属性“top”
- 主干无法读取属性'属性'主干视图中的未定义错误
- 如何克服javascript中的未定义错误
- require未定义错误
- 单击链接时出现函数未定义错误
- 函数为未定义错误
- 主干未定义错误
- 使用Javascript打印HTML:未定义错误
- 避免“无法读取”属性'获取'的未定义错误
- 未捕获类型错误的coffescription:无法读取属性'offsetWidth'的未定义错误
- ajax上get函数内部的未定义错误
- Javascript变量未定义错误
- AngularJS指令作用域未解析(“属性名称未定义”错误)