1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-02-28 01:54:15 +01:00

Fix: When setting deeply nested object properties, where the parent object doesn't yet exist, don't just silently fail. Since we are setting a value, we are at liberty to create the parent object and then set the value - this now does so.

This commit is contained in:
Allan Jardine 2012-06-07 09:43:47 +01:00
parent 29e0d112cb
commit 284658e3c9
2 changed files with 10 additions and 6 deletions

View File

@ -865,11 +865,13 @@
return function (data, val) {
for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
{
data = data[ a[i] ];
if ( data === undefined )
// If the nested object doesn't currently exist - since we are
// trying to set the value - create it
if ( data[ a[i] ] === undefined )
{
return;
data[ a[i] ] = {};
}
data = data[ a[i] ];
}
data[ a[a.length-1] ] = val;
};

View File

@ -440,11 +440,13 @@ function _fnSetObjectDataFn( mSource )
return function (data, val) {
for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
{
data = data[ a[i] ];
if ( data === undefined )
// If the nested object doesn't currently exist - since we are
// trying to set the value - create it
if ( data[ a[i] ] === undefined )
{
return;
data[ a[i] ] = {};
}
data = data[ a[i] ];
}
data[ a[a.length-1] ] = val;
};