0

コレクションの配列 (coll_array) があります。すべてのコレクションは、すべてのイベントで同じ関数 (process_coll) にバインドされます。つまり、配列内のコレクションのいずれかを変更すると、同じ関数が実行されます。私の問題は、イベントが発生したコレクションをどのように特定するかです。ターゲット関数に引数を渡すことができれば、コレクションの ID を渡すことができますが、私が知る限り、バックボーン イベントでそれを行う方法はありません。

initialize: function(){
    _(this).bindAll('process_coll');
    coll_array ; //array of collections 
    for(var i=0;i<coll_array.length;i++)
        coll_array[i].bind('all', this.process_coll);
        coll_array[i].fetch();
}

process_coll: function(){
    //some code here 
    //how do I get the specific collection which resulted in execution of this function?
}
4

1 に答える 1

1

特定のイベントをリッスンする方がよいでしょう。

initialize: function(){
    coll_array ; //array of collections 
    for(var i=0;i<coll_array.length;i++)
        coll_array[i].bind('reset', this.reset_coll);
        coll_array[i].bind('add', this.add_coll);
        coll_array[i].bind('remove', this.remove_coll);
        coll_array[i].fetch();
}

reset_coll: function(collection, options){
    // collection argument is the one you want
}
add_coll: function(model, collection, options){
    // collection argument is the one you want
}

remove_coll: function(model, collection, options){
    // collection argument is the one you want
}
于 2013-02-18T14:11:12.283 に答える