我有模特,商店和网格:
MODEL
Ext.define('demo.mdlTemaco', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string' , mapping: ''},
{name: 'id_empresa', type: 'string' , mapping: ''},
{name: 'cif', type: 'string' , mapping: ''},
{name: 'acronimo', type: 'string' , mapping: ''},
{name: 'competidor', type: 'string' , mapping: ''},
{name: 'descripcion', type: 'text' , mapping: ''}
]
});
商品
Ext.define('demo.strTemaco', {
extend: 'Ext.data.Store',
model: 'demo.mdlTemaco',
autoLoad: false,
autoSync: true,
proxy: {
type: 'ajax',
pageParam: undefined,
startParam: undefined,
limitParam: undefined,
api: {
read: 'read.php',
update: 'update.php',
create: ''
},
reader: {
type: 'json',
root: 'data',
idProperty: 'id',
totalProperty: 'total',
successProperty: 'success',
messageProperty : 'message',
},
writer: {
root: 'records',
encode: true,
writeAllFields: true
}
}
});
GRID
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{
clicksToEdit: 2
});
Ext.create('Ext.grid.Panel', {
itemId:'viewGridTemaco',
title:'<span style="color:#C85E00;">Title</span>',
store: Ext.create('demo.strTemaco'),
stripeRows: true,
loadMask: true,
selType: 'checkboxmodel',
plugins: [cellEditing],
columns:{
defaults:{
hideable:false,
draggable:false
},
items:[
{header:'<span style="color:#C85E00;">Id</span>' ,dataIndex:'id' ,itemId:'IdConcurso' ,flex:1 },
{header:'<span style="color:#C85E00;">Empresa</span>' ,dataIndex:'id_empresa' ,itemId:'Empresa' ,flex:1 },
{header:'<span style="color:#C85E00;">CIF</span>' ,dataIndex:'cif' ,itemId:'CIF' ,flex:2 ,editor:{allorBlanck:false}},
{header:'<span style="color:#C85E00;">Acronimo</span>' ,dataIndex:'acronimo' ,itemId:'Acronimo' ,flex:2 ,editor:{allorBlanck:false}},
{header:'<span style="color:#C85E00;">Competidor</span>' ,dataIndex:'competidor' ,itemId:'Competidor' ,flex:3 ,editor:{allorBlanck:false}},
{header:'<span style="color:#C85E00;">Descripcion</span>',dataIndex:'descripcion' ,itemId:'Descripcion' ,flex:3 ,editor:{allorBlanck:false}}
]
}
renderTo: Ext.getBody()
});
在我的控制器中,我有一个监听器来处理单元格的编辑:
Ext.ComponentQuery.query('viewGridTemaco')[0].getStore().addListener('update',function(store, record, operation, modifiedFieldNames, eOpts){
store.commitChanges();
},this);
在更新php中,如果出于某些原因出错,我发送:
echo json_encode(array(
"success" => //A number between 1-5 depending on the error
));
我想在控制器中处理这个响应以显示一个消息框。有关如何执行此操作的任何想法吗?
答案 0 :(得分:1)
最后我解决了在商店和控制器中禁用autoSync的问题,在我使用的更新侦听器中:
store.sync({
scope:this,
success : function(response){
},
failure:function(response){
var mensaje;
switch(Ext.JSON.decode(response.operations[0].error))
{
case 1:
mensaje="Messagge 1";
break;
case 2:
mensaje="Messagge 2";
break;
case 3:
mensaje="Messagge 3";
break;
case 4:
mensaje="Messagge 4";
break;
}
Ext.Msg.show({
title: 'ADVERTENCIA',
msg:mensaje,
icon: Ext.MessageBox.WARNING,
buttons: Ext.Msg.OK,
closable:false
});
store.rejectChanges();
}
});
我的update.php响应是:
echo json_encode(array(
"success" => false,
"message" => //number between 1-5
));