0

Hello,

there is overridden collection fetch function.

fetch: function() {

        var collection = this;

       $.getJSON(this.url, function(data) {


              // do some processing to data here


          collection.reset(data);
       });
    },

I need to do processing when I get data, so thats why overrride. But the thing - is - the models change event is not triggered, here ,so models do not see and do not render.

I could call proably render method in the getJSON callback but its not they way it should be I guess. How to make here model change event?

1
Contributor
1
Reply
3
Views
4 Years
Discussion Span
Last Post by McLaren
1

in the view class initialize method I did this

this.listenTo(Cars, 'reset', this.addAll); 

addOne: function(car) {

  var view = new CarView({model: car});

  this.$("#cars").append(view.render().el);
},

// Add all items in the **Cars** collection at once.
addAll: function() {
  Cars.each(this.addOne, this);
},

so the reset is triggered when I called reset method in the fetch. View listens to reset and creates view items and draws them.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.