Created
June 8, 2011 07:41
-
-
Save ramontayag/1013977 to your computer and use it in GitHub Desktop.
serialize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
serialize: function(o) { | |
o = o || {}; | |
var ret = []; | |
$(this.element).children('li').each(function() { _recursiveItems($(this)); }); | |
return ret.join("&"); | |
function _recursiveItems(li) { | |
var id = li.attr("id"); | |
var parentId = 'root'; | |
var parent = li.parent(o.listType).parent('li'); | |
if (parent.length > 0) { | |
parentId = parent.attr('id'); | |
} | |
children_list_items = li.children(o.listType).children('li') | |
var position = li.index(); | |
if (children_list_items.length > 0) { | |
children_list_items.each(function() { | |
_recursiveItems($(this)); | |
}); | |
} | |
var resource = li.attr("id").match(o.expression || (/(.+)[-=_](.+)/)); | |
var resourceName = o.key || resource[1]; | |
var serializedId = '[' + id +']'; | |
var container = resourceName + serializedId; | |
ret.push(container + '[parent_id]='+ parentId); | |
ret.push(container + '[position]='+ position); | |
//return item; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ramontayag,
sorry for being so late to this gist, but it so happens that I just stumbled upon your improvements and they really helped me.
Could you give me a hint on how to get the level of
My database asks for
~ item_id
~ parent_id
~ position
and
~ level (depth)
I don't know how to get this last one working.
There is a "_getLevel" function in the code, but I can't get it to work.
If you could help me with this, I would really appreciate.
Kind Regards,
Stefan