Javascript ExtJs 4.2可编辑网格处理响应
我有一个模型、一个商店和一个网格: 型号Javascript ExtJs 4.2可编辑网格处理响应,javascript,php,extjs,extjs4.2,Javascript,Php,Extjs,Extjs4.2,我有一个模型、一个商店和一个网格: 型号 Ext.define('demo.mdlTemaco', { extend: 'Ext.data.Model', fields: [ {name: 'id', type: 'string' , mapping: ''}, {name: 'id_empresa', type: 'string' ,
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
}
}
});
网格
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()
});
在更新php中,如果由于某些原因出现错误,我会发送:
echo json_encode(array(
"success" => //A number between 1-5 depending on the error
));
我想在控制器中处理此响应以显示一个消息框。知道如何执行此操作吗?最后,我解决了在存储区和控制器中禁用自动同步的问题,在我使用的更新侦听器中:
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
));
根据ExtJS文档,
success
属性必须是布尔值。我已将“success”=>1更改为“success”=>true,但在控制器中,我控制此成功的位置和方式为true/false?在store sync回调中,该回调不能与autoSync:true
一起使用。您自己找到了!:)但仅针对以下行:response.operations[0]。error
尝试使用response.operations[0]。getError()
。更好的是,迭代槽操作,因为您永远不知道sync()是否不会执行更多操作。。。
echo json_encode(array(
"success" => false,
"message" => //number between 1-5
));