Ext JS 4: Override the format of data sent to the server

I am creating a simple admin user interface using Ext JS 4. I started with this example from the Sencha website. I added a group of labels to the form (with four options), and I have fields that are dynamically checked based on the selected record in the grid below the form. Everything works correctly, but when I send data to the server, the format of the data from the group of flags depends on which button is clicked.

For example, when I edit a record and press the save button, Ext JS sends an array with true / false values ​​corresponding to the checkboxes set:

{"available": [true, true, false, false]} 

When I create a completely new record and click the add button, Ext JS sends an array with the names of the checked flags:

 {"available": ["Selection_1", "Selection_2", "Selection_3"]} 

Finally, if I create a new record and click the "Add" button, but only checks ONE, Ext JS sends one string value (unlike the array that it sent in the second example):

 {available": "Selection_1"} 

Why does Ext JS do this? This makes it difficult to work with data on the server side. Also, is there a way I can override the way data is sent to the server so that it sends it in the same format as the add button? Thanks!

+4
source share
1 answer

You can use allowSingle: false to ensure that all write operations send an array of records regardless of the number of records. Here is the API document: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.writer.Json-cfg-allowSingle

Regarding the values ​​to send. I don’t quite understand what is going on here, but you may want to explore this function: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.CheckboxGroup-method-getSubmitData

EDIT: Another note - the checkboxes use inputValue to figure out what to submit to the submit form. Check the configuration of this property.

+2
source

Source: https://habr.com/ru/post/1443070/


All Articles