Я написал программу сыпучие Backbone.js:Backbone.js Uncaught TypeError
<script>
var PostModel = Backbone.Model.extend();
var PostView = Backbone.View.extend({
template: _.template($('#posttemplate').html()),
intialize: function() {
console.log("intializing view");
},
render: function() {
console.log("rendering..");
var htmloutput = this.template(this.model.toJSON());
$('#postcontainer').html(htmloutput);
return this;
}
});
$(document).ready(function() {
var postmodel = new PostModel({title: "hello"});
var postview = new PostView({model: postmodel});
postview.render();
});
</script type="text/javascript">
<script type="text/template" id="posttemplate">
<div> Title: <%= title %> , post: <%= post %> </div>
</script>
<div class="container" id="postcontainer"></div>
когда я запускаю код я получаю следующее сообщение об ошибке:
Uncaught TypeError: Не удается прочитать свойство «заменить» из undefined
но он отлично работает, когда я положил template = _.template ($ ('# posttemplate'). html()); в функцию рендеринга.