Reputation: 11797
I am getting the following error : Uncaught TypeError: Object #<Object> has no method 'bind'
with backbone.
var UpdatingPostView = PostView.extend({
initialize: function (options) {
this.render = _.bind(this.render, this);
this.model.bind('change:title', this.render);
}
});
Here is the calling function(s).
posts.fetch().complete(function() {
var postCollectionView = new PostCollectionView({
collection: posts,
el: $('.posts')[0]
});
postCollectionView.render();
});
Here is PostCollectionView
var PostCollectionView = Backbone.View.extend({
initialize: function (post) {
var that = this;
this._postViews = [];
this.collection.each(function() {
that._postViews.push( new UpdatingPostView({
model: post,
tagName: 'div'
}));
});
},
render: function () {
var that = this;
//Clear out this element
$(this.el).empty();
//Render each view and append to parent element
_(this.postViews).each(function (dv) {
$(that.el).append(dv.render().el);
})
}
Upvotes: 0
Views: 695
Reputation: 239402
What is post
here?
initialize: function (post) {
var that = this;
this._postViews = [];
this.collection.each(function() {
that._postViews.push( new UpdatingPostView({
model: post,
When you instantiated this earlier, you did so with...
var postCollectionView = new PostCollectionView({
collection: posts,
I'm not an expert on Backbone, but I'm pretty certain it isn't wired up to pass a singular post to the initializer of a collection which is passed an array of posts.
I think your initializer should probably look something like this:
initialize: function () {
var that = this;
this._postViews = [];
this.collection.each(function(post) { // <<<<< function(post) is important
that._postViews.push( new UpdatingPostView({
model: post,
Upvotes: 1