palmic
palmic

Reputation: 1856

uploadify + backbone events problem

I have a multiple files uploadify setting with:

'onComplete' : function(event, ID, fileObj, response, data) {
    myCollection.add({params parsed from response json});
}

which triggers (trough this.collection.bind('add', this.add)) this collection view method:

add: function(obj) {
    var view = new MyModelView({model: obj});
    this.$('.insert-models-here').append(view.render().el);
    return this;
},

The new MyModelView call triggers: MyModelView::initialize() which is here:

initialize: function() {
    var t = $('#photo-template').html();
    this.template = _.template(t);
    this.model.view = this;
},

And every _.template() calls jumps inside __flash__toXML() method from which all thread is stopped. The result is no model added inside my collection from any uploadify event.

Does anyone knows why and how to avoid this?

Upvotes: 1

Views: 443

Answers (1)

palmic
palmic

Reputation: 1856

Ok, I found solution.

Problem was in using underscore in uploadify events so I replace underscore _.templates with icanhaz and rewrite my add() collection view method this way to workaround any underscore functionality:

    add: function(obj) {
        var view = new MyModelView({model: obj});
        $('.insert-models-here').first().append(view.render().el);
        return this;
    },

Hope someone will call my name in future..

Upvotes: 4

Related Questions