亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于backbone collection的疑問?

關于backbone collection的疑問?

翻閱古今 2018-10-18 17:18:03
var ListView = Backbone.View.extend({            initialize: function() {                if(this.collection) {                    this.byId = {};                    this.views = [];                    this.collection.each(this.registerView,this);                }            },            registerView: function(model) {                var view = new ItemView({model: model});                this.byId[model.cid] = view;                this.views.push(view);            },            render: function() {                var self = this;                this.$el.empty();                _.each(this.views, function(view) {                    $_el = view.render().$el;                    self.$el.append($_el);                });            }        });                var aView = new ListView({el: "#alist", collection: alist});        aView.render();this.collection.each方法第二個參數傳this,代表什么意思?第一個參數直接調用registerView方法,方法里沒有傳model,那model是從哪里來的呢?
查看完整描述

1 回答

?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

你找找文檔吧。

this.collection.each方法第二個參數傳this,代表什么意思? 
答:我猜這個應該是一個綁定上下文的。

registerView方法,方法里沒有傳model。
答:就和jquery的each一樣。里面他是會傳參數的。比如這樣$(selector).each(function(index,element))


查看完整回答
反對 回復 2018-11-08
  • 1 回答
  • 0 關注
  • 463 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號