mirror of
https://github.com/DataTables/DataTables.git
synced 2025-03-15 16:29:16 +01:00
Dev fix - Full backwards compatiblity with fnServerParams with array
syntax paraneter names - Data added using fnServerParams with array syntax had different behaviour in 1.10 from 1.9. In 1.9 jQuery would create an array for us, but in 1.10 before we create an object first, we need to create that array ourselves. So the following code had different behaviour: "sAjaxSource": "data/arrays.txt", "fnServerParams": function ( d ) { d.push( {name: 'somekey[]', value: 'somevalue1'}, {name: 'somekey[]', value: 'somevalue2'} ); } In 1.10 it would have sent `somekey[] = somevalue2` but 1.9 would have sent both as part of an array. To maintain full compatiblity with 1.9 we need to convert this syntax to an array - this commit does that. I was concerned about using parameters in the brackets, but jQuery only searches for `[]` when performing this conversion. We could use $.param and then decode the created query string, which would be absolutely 100% comaptible, but would involve additional code and I think this method provides that 100% compatiblity from reading the jQuery code), and its shorter.
This commit is contained in:
parent
19f5d9a157
commit
d4a1028a1d
@ -1 +1 @@
|
||||
667ebcafa99f93bb2be04892ec8be75161a04921
|
||||
a3f57e46e1a0429dc63527ce1ea125925226eaa3
|
||||
|
15
media/js/jquery.dataTables.js
vendored
15
media/js/jquery.dataTables.js
vendored
@ -2211,8 +2211,23 @@
|
||||
// Convert to object based for 1.10+ if using the old scheme
|
||||
if ( data && data.__legacy ) {
|
||||
var tmp = {};
|
||||
var rbracket = /(.*?)\[\]$/;
|
||||
|
||||
$.each( data, function (key, val) {
|
||||
var match = val.name.match(rbracket);
|
||||
|
||||
if ( match ) {
|
||||
// Support for arrays
|
||||
var name = match[0];
|
||||
|
||||
if ( ! tmp[ name ] ) {
|
||||
tmp[ name ] = [];
|
||||
}
|
||||
tmp[ name ].push( val.value );
|
||||
}
|
||||
else {
|
||||
tmp[val.name] = val.value;
|
||||
}
|
||||
} );
|
||||
data = tmp;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user