首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Backbone.js -查看备注

Backbone.js -查看备注
EN

Stack Overflow用户
提问于 2012-11-02 16:09:59
回答 1查看 80关注 0票数 0

我一直在遵循一些教程,以便在backbone.js中将视图与模型绑定,但是当我在模型上设置新属性时,我的视图不会更改。

我目前在控制台中工作,正在将"tr“添加到"table”中。设置的新属性后,仅当我重新追加时更改才会出现。

代码如下:

代码语言:javascript
复制
window.ListView = Backbone.View.extend({

tagName:"tr",
template: _.template("<td><%= first%></td><td><%= last%></td><td><%= sex%></td><td><%= height></td><td><%= weight%></td>"),



initiliaze: function(){
    _.bindAll(this, 'render');
    this.model.bind('change', this.render, this);
    this.template = template.html;


},

render:function () {
    this.$el.html(this.template(this.model.toJSON()));
    return this;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-02 21:17:50

删除this.template = template.html行,您的代码就可以正常工作

代码语言:javascript
复制
window.ListView = Backbone.View.extend({

tagName:"tr",

template: _.template("<td><%= first%></td><td><%= last%></td><td><%= sex%></td><td><%= height></td><td><%= weight%></td>"),

initiliaze: function(){

    _.bindAll(this, 'render');
    this.model.bind('change', this.render, this);
    //this.template = template.html;
},

render:function () {

    this.$el.html(this.template(this.model.toJSON()));
    return this;
} 

}); `
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13191497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档