1

我正在尝试在 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 )
    });
    },

如果可能的话,我也想将数据发回,以便将这些值包含到搜索屏幕中。

4

1 回答 1

2

如果您尝试将状态保存回服务器,则需要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);
  }
});
于 2013-10-31T22:45:19.467 回答