0

私はバックボーン Web アプリ (バックボーンにはかなり新しい) を介して作業しており、コレクションを取得するときにコレクションを反復処理する際に助けが必要です。私がやりたいことは、コレクション内の各要素をループし、progress属性がimport を100表示する場合<div>、それ以外の場合は loading を表示すること<div>です。

次のように、コレクションの最後の要素に対してこれを機能させます。

fileRepositoryCollection.fetch({

    success: function () {

        if (fileRepositoryCollection.at(fileRepositoryCollection.length - 1).get('progress') === 100) {
            $('#loading').hide();
            $('#imported').show();
        } else {
            $('#loading').show();
            $('#imported').hide();
        }
    }
});
4

1 に答える 1

1

コレクション クラスで html をレンダリングしないでください。コレクション ビューには、コレクションが html でどのように表示されるかを定義する、レンダリング用の render メソッドが必要です。次に、ビューでコレクションを反復処理します。

このようなもの:

var fileRepositoryCollectionView = Backbone.View.extend({

    render: function() {
        // collection rendering

        this.collection.each(function(file) {
           if (file.get('progress') === 100) {
                $('#loading' + file.get('some_id')).hide();
                $('#imported' + file.get('some_id')).show();
            } else {
                $('#loading' + file.get('some_id')).show();
                $('#imported' + file.get('some_id')).hide();
            }
        });

        return this;
    },
});

var repView = new fileRepositoryCollectionView({ collection: fileRepositoryCollection});
于 2013-04-27T16:11:00.873 に答える