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