backbone.js view renders before model fetch

前端 未结 5 976
自闭症患者
自闭症患者 2021-01-05 15:51

I\'m trying to make a small backbone.js app, but struggle with the order of things.

In my html file, I have two script blocks in the header:



        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 16:09

    Resets the model's state from the server. Useful if the model has never been populated with data, or if you'd like to ensure that you have the latest server state. A "change" event will be triggered if the server's state differs from the current attributes. Accepts success and error callbacks in the options hash, which are passed (model, response) as arguments.

    In this case, you'll want to render the view in the success callback.

    model.fetch({
       error: function () {
       },
       success: function (model, response) { // model is ready now
          // do view stuff here
       }
    });
    

提交回复
热议问题