javascript - Is there are proper way to $.extend a nested properties in jQuery? -


what have , need. it's easy.

the default options (there nested properties):

{   sdom: 'frt<"tfoot"lp>',   binfo: false,   spaginationtype: "full_numbers",   olanguage: {     ssearch: "",     slengthmenu: "show _menu_",     opaginate: {       sfirst:     "|<<",       slast:      ">>|",       snext:      ">>",       sprevious:  "<<"     }   } } 

actual options:

{   olanguage: {     opaginate: {       snext:      "modified"     }   } } 

the result of $.extend:

{   sdom: 'frt<"tfoot"lp>',   binfo: false,   spaginationtype: "full_numbers",   olanguage: {     opaginate: {       snext:      "modified"     }   } } 

what need extend defaults options actual options , following result (one property has been modified):

{   sdom: 'frt<"tfoot"lp>',   binfo: false,   spaginationtype: "full_numbers",   olanguage: {     ssearch: "",     slengthmenu: "show _menu_",     opaginate: {       sfirst:     "|<<",       slast:      ">>|",       snext:      "modified"       sprevious:  "<<"     }   } } 

the problem $.extend function ignores nested properties , operates first-level properties. have manually $.extend each of nested properties, guess not solution.

you need a recursive copy passing true first parameter:

var defaults = {...} var actual = {...}  //recursively merge blank object console.log($.extend(true,{}, defaults, actual))​ 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -