PDA

View Full Version : JsonStore and successProperty :@



strato1986
25 Aug 2009, 11:39 AM
Im having real troubles to get this working.. if i delete a record it fires the "write" event!
but when i "add" or "insert" it doesnt! and i need to be able to read the successProperty result... here i leave the code and the json result when im adding a record...



var reader = new Ext.data.JsonReader(
{
totalProperty: 'total',
idProperty: 'idGrupo',
root: 'datos'
},
[{name: 'idGrupo'},
{name: 'nombreGrupo', allowBlank: false},
{name: 'cantidadUsuarios'},
]);

var RecGrupo = Ext.data.Record.create(['nombreGrupo']);


var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});


var store = new Ext.data.Store({
id : 'grupos-store',
autoLoad : false,
autoSave : true,
restful : true,
proxy : new Ext.data.HttpProxy({
url :'index.php/grupos_rest/grupos/format/json',
listeners : {
write : function(store, action, result, response, rs) {
alert(response.success, response.message);

}
}
}),
reader : reader,
writer : writer,
listeners : {
add : function(store,record,index){

},
}
});



var grid = new Ext.grid.EditorGridPanel({
id : 'grupos-grid',
store : store,
viewConfig: {forceFit: true},
columns : [ {header: 'Nombre del Grupo',dataIndex:'nombreGrupo'},
{header: 'Cantidad de Usuarios',dataIndex:'cantidadUsuarios'}],
height : 300,
sm : new Ext.grid.RowSelectionModel({singleSelect:true}),
tbar : [{
text : 'Agregar Grupo',
iconCls : 'silk-group-add',
scope : this,
handler : function(){
Ext.Msg.prompt('Grupo','Ingrese el nombre del nuevo grupo:',function(btn,texto){
if (btn=="ok"){
if (Ext.util.Format.trim(texto) == ""){
alert("no puede estar vacio.")
} else {
//CREATE RECORD
var grid = Ext.getCmp('grupos-grid');
var g = new RecGrupo({"nombreGrupo" : texto});
grid.getStore().add(g);

}
}
})
}
},{
text : 'Eliminar Grupo',
iconCls : 'silk-group-delete',
scope : this,
handler : function(){
var grid = Ext.getCmp('grupos-grid');
var rec = grid.getSelectionModel().getSelected();
if (!rec) {
return false;
}
grid.store.remove(rec);

}
},{
text : 'Refrescar Datos',
iconCls : 'silk-arrow-refresh',
scope : this,
handler : function(){
Ext.getCmp('grupos-grid').store.reload();
}
}]
});

grid.relayEvents(this.store, ['destroy', 'save', 'update']);


and the json result...


{"success":true,"message":"Ok!"}


but when i add a record it doesnot fire the "write" event... someone knows why this happens?

sorry for my lousy english :P

johnd2i
1 Dec 2009, 4:30 PM
Adding a record will not fire the write event. Rather it will fire the add event on the store.