PDA

View Full Version : Extraparams and model save



nocturn
10 Apr 2012, 9:53 AM
Hi
I was wondering if there is any way to pass an array of objects as extra param of model.save method ?
For simple types params seem to work.


Ext.define('RightGridModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'rightText', type: 'string'},
{name: 'digit',type:'int'}
]
});
var mod = Ext.create('RightGridModel');
mod.set('rightText', 'some text');
mod.save({
url: "Home/Insert",
params: {
par: 'additional parameter'
}
});


However if I want to send and array as an extra param,(of course I changed server side function to be approperiate ) par variable is an empty list. Here is a code I use to send an model and array



mod.save({
url: "Home/Insert",
params: {
par: Ext.encode(array)
}
});

Is there any way to send a model and an array as extra parameter ?? What is the best way to achieve that ?

scottmartin
10 Apr 2012, 10:13 AM
Sure, just create the array and send it.



var myarray = [];
myarray.push({ field: value });

rec.save({
params: {
mydata: Ext.encode(myarray);
}
});


Regards,
Scott

nocturn
10 Apr 2012, 12:30 PM
Unfortunately it's not working. In the first post I wrote I tried this. To be sure I checked it again, but it still doesnt work
Edit
It only works if I send simple types, like int or string. However sending objects in array is not working

scottmartin
10 Apr 2012, 12:50 PM
Are you having problems on the server side grabbing the data, or are you saying that the data is not sent? Do you inspect the traffic to the server using Firebug/Developer Tools?

Example:



params: {
sort: '[{"property":"user_name","direction":"ASC"}]'
}

function get_json_value($json,$key)
{
$result = NULL;
if(function_exists('json_decode')) {
$jsonData = json_decode($json, TRUE);
$result = $jsonData[0][$key];
}
return $result;
}

$sort = (isset($_POST['sort']) ? $_POST['sort'] : $_GET['sort']);

$ord = get_json_value($sort,'property');
$dir = get_json_value($sort,'direction');


Regards,
Scott.