-1

Possible Duplicate:
Backbone.js - add parameter sending to fetch not trigger the collection

In my function, eventhough i added the reset to trigger my render function, nothing is happening... any clue me the wrong what i did..?

code:

$(document).ready(function(){

    var school = {};

    school.model = Backbone.Model.extend({
        defaults:{
            name:'name yet to decide'    
        }    
    });

    school.collect = Backbone.Collection.extend({
        model:school.model,
        url:'js/school.json',
        parse:function(response){
            return response;
        }
    });

    school.view = Backbone.View.extend({
        tagName:'div',
        className:'division',
        template:$('#newTemp').html(),
        render:function(){
            var temp = _.template(this.template);
            this.$el.html(temp(this.model.toJSON()));
            return this;
        }
    });

    school.views = Backbone.View.extend({
        el:$('#content'),
        initialize:function(){
            _.bindAll(this);
            this.collection = new school.collect;
            this.collection.bind("reset", this.render);
            this.collection.fetch({
                update:true
            })
        },
        render:function(){
            var that = this;
            _.each(this.collection.models, function(item){
                that.addItems(newItem);
            })
        },
        resets:function(){
            console.log(this.collection.models)
            console.log('calling from resets')    
        },
        addItems:function(item){
            var newItem = new school.collect({model:item});
            this.$el.append(newItem.render().el);
        },
        changed:function(){
            console.log('calling from changed')
        }
    });

    var newSchool = new school.views;
})
Community
  • 1
  • 1
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • Same as: http://stackoverflow.com/questions/14545193/backbone-js-still-parse-get-the-response-from-fetch-success-and-render-functio, http://stackoverflow.com/questions/14460449/backbone-js-add-parameter-sending-to-fetch-not-trigger-the-collection, http://stackoverflow.com/questions/14457874/backbone-how-get-this-sort-out-some-part-still-not-clear, http://stackoverflow.com/questions/14453219/backbone-js-change-not-triggering-while-the-name-change, http://stackoverflow.com/questions/14398417/backbone-js-not-appending-elements-still-the-data-console-properly – jevakallio Jan 28 '13 at 08:19
  • 2
    ^ All your own questions by the way. – jevakallio Jan 28 '13 at 08:21

1 Answers1

2

As on Backbone.js 1.0.0 You listen to reset but pass {reset:true} option.

When the model data returns from the server, the collection will be (efficiently) reset, unless you pass {update: true}, in which case it will use update to (intelligently) merge the fetched models

http://backbonejs.org/#Collection-fetch

Venkat Kotra
  • 10,413
  • 3
  • 49
  • 53
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55