问题
I have a question.
I need to send a json format to my backend service. It requires something i haven't managed to create. What i am sending with a form is this:
{
"jobs": {
"name": "dsvs",
"jobType": "CUSTOM",
"description": "sdvsdv",
"tasks": "14,15,16"
}
}
but what i need to send is
{
"jobs": {
"name": "dsvs",
"jobType": "CUSTOM",
"description": "sdvsdv",
"tasks": [14,15,16]
}
}
how can i do this?
This is my form handler:
handler: function () {
var form = this.up('form').getForm();
var formData = Ext.encode(form.getValues());
Ext.Ajax.request({
url: ND.url + 'dna/rjs/secure/service/rest/jobs.json',
method: 'POST',
waitTitle: 'Connecting',
waitMsg: 'Sending data...',
jsonData: {
jobs: form.getValues()
}
});
})
I hope anyone has an idea!
回答1:
You can't by "honest" ways.
You can, however, hack it into that one.
handler: function () {
var form = this.up('form').getForm();
var formData = Ext.encode(form.getValues());
formData.jobs.tasks = formData.jobs.tasks.split(',');
Ext.Ajax.request({
url: ND.url + 'dna/rjs/secure/service/rest/jobs.json',
method: 'POST',
waitTitle: 'Connecting',
waitMsg: 'Sending data...',
jsonData: {
jobs: formData
}
});
})
You don't use your formData in your example, despite having it, BTW.
That would result in:
{
"jobs": {
"name": "dsvs",
"jobType": "CUSTOM",
"description": "sdvsdv",
"tasks": ["14","15","16"]
}
}
If that is still not suitable, than you can further hack it by calling parseInt on each task value.
EDIT:
Added clarification.
来源:https://stackoverflow.com/questions/7340009/adjusting-json-format-send-by-extjs-form