mardi 4 août 2015

Have got some problems with sorting and rendering data with backbone.js

Have got some problems with sorting and rendering data with backbone.js There is sorting by 'title' in comparator. This.model.collection has models after sorting by title, but when rendering starts models views after sorting by order.

    var TodoList = Backbone.Collection.extend({

    model: Todo,

    comparator: function(todo) {
        return todo.get('title');
    }

    });

    var TodoView = Backbone.View.extend({

    tagName:  "li",

    template: _.template($('#item-template').html()),

    initialize: function() {
        this.listenTo(this.model, 'change', this.render);
        this.listenTo(this.model, 'destroy', this.remove);
    },

    render: function() {
        this.$el.html(this.template(this.model.toJSON()));
        return this;
    }
    });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire