我正在使用Store
具有声明的代理api
。我可以使用 处理异常exception listener
,但是当成功删除记录时,如何向用户发送消息?
我的商店看起来像:
Ext.define('ContatosApp.store.PsContatosStore', {
extend: 'Ext.data.Store',
requires: [
'ContatosApp.model.PsContatosModel'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'ContatosApp.model.PsContatosModel',
storeId: 'MyJsonStore',
pageSize: 15,
trailingBufferZone: 20,
proxy: {
type: 'ajax',
api: {
read: 'contact/list',
create: 'contact/save',
update: 'contact/update',
destroy: 'contact/delete'
},
directionParam: 'order',
limitParam: 'max',
startParam: 'offset',
url: '',
reader: {
type: 'json',
root: 'contatos'
},
writer: {
type: 'json',
root: ''
},
listeners: {
exception: {
fn: me.onAjaxException,
scope: me
}
}
}
}, cfg)]);
},
onAjaxException: function(proxy, response, operation, eOpts) {
var data = Ext.JSON.decode(response.responseText);
Ext.MessageBox.show({
title: 'Error',
msg: data.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
});
我的删除按钮处理程序是:
var grid = Ext.ComponentQuery.query('#MyGridPanel');
var selection = grid[0].getSelectionModel().getSelection()[0];
if (selection) {
Ext.getStore('PsContatosStore').remove(selection);
}
另外,如果我从商店中删除记录,但 ajax 调用返回错误,我需要重新加载网格以再次显示记录,或者有更好的方法来处理这个问题?