我不确定为什么this.model
在我的骨干视图中未定义。
这是我的剧本:
var TheModel = Backbone.Model.extend({
defaults: {
f_Name: "Darth"
},
parse: function(response) {
console.log('parsing');
}
});
var TheView = Backbone.View.extend({
el: '.js-container',
intialize: function() {
this.model = new TheModel();
debugger;
},
template: _.template( $('#form-template').html() ),
render: function() {
var self = this;
this.$el.html( this.template({settings: this.model.toJSON()}) );
return this;
}
});
var theView = new TheView();
theView.render();
这是我的模板:
<div class="js-container">
</div>
<script type="text/template" id="form-template">
<h1>Form</h1>
<form action="" method="Post">
<div>
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="fName" />
</div>
</form>
<div>
Name = <%- settings.f_Name %>
</div>
</script>
答案 0 :(得分:1)
你拼写&#39;初始化&#39;错