Backbone return this;
来源:互联网 发布:上海网络通信设备公司 编辑:程序博客网 时间:2024/06/14 05:55
var ItemView = Backbone.View.extend({ events: {}, render: function(){ this.$el.html(this.model.toJSON()); return this; }});
这里return this;的作用:可以让我们把ItemView作为子view重复使用。我们也可以利用它在呈现之前做预渲染(pre-render)。
重复使用ItemView的例子:
var ListView = Backbone.View.extend({ render: function(){ // 假定items是model暴露的需要呈现的list var items = this.model.get('items'); // 使用Underscore的_each方法遍历每个item _.each(items, function(item){ // 创建一个新的ItemView实例,传入指定的model项 var itemView = new ItemView({ model: item }); // itemView的DOM元素渲染之后追加到ListView的el中。 // 这里'return this'可帮助在render之后访问到它的输出("el") this.$el.append( itemView.render().el ); }, this); }
如果不使用return this; ListView需要这样写:
var ListView = Backbone.View.extend({ render: function(){ var items = this.model.get('items'); _.each(items, function(item){ var itemView = new ItemView({ model: item }); itemView.render(); this.$el.append(itemView.el ); }, this); }
0 0
- Backbone return this;
- return this与return *this
- return *this和return this
- return *this和return this
- return this.vercode
- return this的用法
- return this.each(function(){})
- Java return this
- getThis() { return this;}//getSuper() { return super.getThis();
- Backbone
- backbone
- backbone
- Backbone
- backbone
- backbone
- backbone
- Backbone
- Backbone
- Linux常用命令大全
- 数组排序,并返回排序后的数组对应原数组的下标(c语言)
- 回文链表
- My97DatePicker 的简单使用
- 先来个链接,按上面的来做吧
- Backbone return this;
- MyEclipse 下安装外置的jdk7
- 丁仿:PMP考试中的重头戏:变更管理专项突破!备考学员必备!!
- AndroidStudio安装遇到的拦路虎
- Xcode6以后如何用企业证书发布应用
- HTML <a> 标签的 href 属性
- Jquery实际应用,判断radio,selelct,checkbox是否选中及选中的值
- [异常] Java文件上传异常org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of mul
- php不提示报错