For the moment I wrote this function that converts a plain object like
{a.b:1,a.c:2,a.d.b:3} into {a:{b:1,c:2,d:{b:3}}
function plainToNestedObject(plain){
var result = {};
$tw.utils.each(plain,
function(value,key){
createChilds(result,key.split('.'),value)
});
return result;
function createChilds(ob,keys,value){
keys = keys.slice(); // no side effects please
var lastKey = keys.pop(); //pop is handy but mutates the array
var lastChild = keys.reduce(
function(ob,k){
ob[k] = ob[k] || {};
return ob[k];
}
,ob);
lastChild[lastKey] = value;
return ob;
}
}
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/f7b7e769-728d-4b7d-8be3-dded8d9248b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.