0

私はこのコレクションを持っています

var Product = Backbone.Model.extend({
           urlRoot:'/api/products',
           idAttribute:'id'
        });
    var Products = Backbone.Collection.extend({
        model:Product,
        url : '/api/products/'
    });

サーバーからモデルを取得します

var products = new Products();
products.fetch();

ある時点で、サーバー上のデータを変更し、「製品」に新しいデータを持たせたい (コレクションを更新する)。私はこのようなことを試しました

products.reset()
products.fetch()

しかし、この製品の後は空です。助けてください

4

2 に答える 2

0

サーバーが時間内に応答しない可能性があります。データをリセットする正しい方法は次のとおりです。

products.fetch({reset: true}).success(function(response){
  // update the view here if necessary
})
于 2013-10-02T12:43:49.443 に答える
0

productsサーバーがデータを返す前にコンテンツをチェックしている可能性があります。代わりproductsに、コールバックでまだ空かどうかを確認します。success

products.fetch({
    success: function() {
        console.log(products.toJSON()); //is it still empty here? 
    }
});
于 2013-10-02T12:35:57.070 に答える