duc*_*cin 1 javascript backbone.js
我在某个地方犯了一个愚蠢的错误,我不能让基础骨干视图得到渲染.有人可以指出我在这段代码中有什么问题吗?
var view = new Backbone.View({
el: 'body',
template: '<p>this is my new template</p>',
render: function() {
console.log('rendering myself');
this.$el.html(this.template);
return this;
}
});
view.render();
Run Code Online (Sandbox Code Playgroud)
PS console.log是空的.
你的语法有点偏,你应该首先定义你的视图然后实例化它.
//define view
var MyView = Backbone.View.extend({
el: 'body',
template: '<p>this is my new template</p>',
render: function() {
console.log('rendering myself');
this.$el.html(this.template);
return this;
}
});
//create view instance
var view = new MyView();
view.render();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
954 次 |
| 最近记录: |