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方法第二個(gè)參數(shù)傳this,代表什么意思?第一個(gè)參數(shù)直接調(diào)用registerView方法,方法里沒(méi)有傳model,那model是從哪里來(lái)的呢?
關(guān)于backbone collection的疑問(wèn)?
翻閱古今
2018-10-18 17:18:03