PDA

View Full Version : create json



fvinson
25 Jun 2012, 2:08 AM
I have an editing grid Panel
The user can change information
when the user modifie value i want add the change in a json object and when he make save, i create a ajax request with this json object


Ext.define('ReactionModif', {
extend: 'Ext.data.Model',
fields: ['id', 'field','oldvalue','newvalue']
});

var storeReactionModif = Ext.create('Ext.data.writer.Json',{model:'ReactionModif'});

mygrid.on('edit', function(editor,e){
var oldV= e.originalValue;
var newV= e.value;
if (oldV != newV) {
var modif= {
id : e.record.get('id'),
field : e.field,
oldvalue : oldV,
newvalue : newV
}
/*when i create a array it's ok but i want a json
//ReactionModif.push([e.record.get('id'),e.field,oldV,newV]);
storeReactionModif.write(modif);
};
});


Thanks

scottmartin
25 Jun 2012, 10:39 AM
Will you be creating the json on the server? You already have the object sent?

Scott.

fvinson
26 Jun 2012, 1:34 AM
I create an array in javascript and after (before send data in ajax) , I encode the array to json
It's ok like this ; I wanted create directly a json data on the client and add data and send this data to the server when user make save.



var ReactionModif= new Array;

var DelReaction = Ext.create('Ext.Action', {
icon : '../javascript/extjs-4.1.0/examples/shared/icons/fam/delete.gif',
text: 'Delete',
disabled: true,
handler: function() {
var nb = gridReaction.getSelectionModel().getSelection().length;
//alert(gridReaction.getSelectionModel().getSelection());
var record="Je modifierais le style des reactions (le Del dans base se fera lors du save : ";
for (var i=0 ; i<nb; i++) {
var rec= gridReaction.getSelectionModel().getSelection()[i];
//alert(rec);
rec.tdCls='x-grid-row-del';
//ajout information de delete dans ReactionModif
ReactionModif.push([rec.get('id'),"del","",""]);
record= record+rec.get('id');
}
alert(record);
}
});

......
var SaveReaction = Ext.create('Ext.Action',{
icon : '../javascript/extjs-4.1.0/examples/shared/icons/fam/save.gif',
text: 'Save',
disabled: true,

handler: function(widget, event) {
var jsonModif= Ext.encode(ReactionModif);
Ext.Ajax.request({
url:'datamodif_v1.php',
params: {Reactions:jsonModif}
});
//remise a zero du tableau des modifs
ReactionModif = new Array;
storeReaction.load();
}
});