簡體   English   中英

如何在調用模型獲取時在主干中創建加載屏幕?

[英]How to create a loading screen in backbone while calling model fetch?

我正在嘗試在this.model.fetch({})發生時設置加載屏幕,不確定如何調用...這是我當前使用事件觸發器的嘗試,但未觸發...

search: function (e) {
      console.log('searching...');
      var eventL = this.vent;
      e.preventDefault();
      var that;

      that = this.model;
      //post instance to the server with the following input fields
      this.model.fetch(
        {data: {
          channel: $('#channel').val(),
          week: $('#week').val(),
          year: $('#year').val(),
          filter: $('#filter').val()
        },
      attack: this.options.vent.trigger('ok', data),
      success: $.proxy(this.storeMusic, this )
    });
    },

如果可能的話,我也想將數據發送回去,因此可以將這些值包括在搜索屏幕中。

如果您嘗試將狀態保存回服務器,則需要save方法而不是fetch save方法(以及fetch )接受成功回調(請參閱文檔 ),您可以使用該回調觸發隱藏加載屏幕的事件。

像這樣:

var self = this;

// About to save, fire event to indicate loading screen should be displayed
this.options.vent.trigger('saveStarted');

this.model.save({
  channel: $('#channel').val(),
  week: $('#week').val(),
  year: $('#year').val(),
  filter: $('#filter').val()
},
{
  success: function(model /*, response, options */) {
    // Save completed, fire event to indicate loading screen should be hidden
    // The model is available as the first parameter of the callback
    self.options.vent.trigger('saveCompleted', model);
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM