Handlebars.compileは。あなたは合格ハンドルエラー
すぎてわからない「未定義なぜ...
HTML
<div id="to-do-app"></div>
<input id="add-to-do-value" type="text" placeholder="Add to do">
<button id="add-to-do">Add</button>
<script type="text/javascript" src="js/handlebars.js"></script>
<script id="to-do-template" type="text/template">
<ul>
{{#this}}
<div>
<li>{{value}}</li>
</div>
{{/this}}
</ul>
</script>
<script type="text/javascript" src="js/app.js"></script>
JS
(function() {
var toDo = {
data: [],
cacheDom: function() {
this.toDoApp = document.getElementById('to-do-app');
this.toDoTemplate = document.getElementById('to-do-template');
this.addToDo = document.getElementById('add-to-do');
this.addToDoValue = document.getElementById('add-to-do-value');
},
render: function() {
this.toDoTemplate = Handlebars.compile(this.toDoTemplate.innerHTML);
this.toDoApp.innerHTML = this.toDoTemplate(this.data);
},
bindEvents: function() {
this.addToDo.addEventListener("click", this.add.bind(this));
},
add: function() {
var toDoValue = this.addToDoValue.value;
if(toDoValue) {
var toDoObj = {
value: toDoValue
}
this.data.push(toDoObj);
}
this.render();
},
init: function() {
this.cacheDom();
this.bindEvents();
this.render();
}
}
toDo.init();
})();