Why fetch() does not work?

前端 未结 2 1277
甜味超标
甜味超标 2020-12-21 16:22

I\'m trying to fetch a collection from a JSON url. The backbone does send the request and does get a response but there are no models in the collection after it

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-21 17:28

    fetchis asynchronous. Try

    stores.fetch({ 
        success:function() {
            console.log(stores.toJSON());
        }
    });
    

    or

    stores.on("sync", function() {
        console.log(stores.toJSON());
    });
    stores.fetch();
    

    or

    stores.fetch().then(function() {
        console.log(stores.toJSON());
    });
    

提交回复
热议问题