Why fetch() does not work?

前端 未结 2 1278
甜味超标
甜味超标 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());
    });
    
    0 讨论(0)
  • 2020-12-21 17:29

    Get rid of the initialize function in your Item class. You don't need it.

    There's no such thing as stores.models -- if you want to see what's in it, you have to do console.log(stores.toJSON());

    0 讨论(0)
提交回复
热议问题