I have a jquery third party application that has nested lists that serialize to an output like below. The list will always only have 2 levels, but I am having trouble trying to figure out how to parse it. I am using coldFusion.
The List Looks like (line breaks added for visualization, they cannot be used as a delimiter):
[{"id":1},
{"id":197,"children":[{"id":198},{"id":199},{"id":200}]},
{"id":2,"children":[{"id":3},{"id":4},{"id":143},{"id":6},{"id":5},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12}]},
{"id":15,"children":[{"id":17},{"id":190},{"id":191},{"id":131},{"id":16},{"id":142},{"id":124}]},
{"id":114}]
I want to loop through each id and convert into a parentid and childid like so:
id:1 parentid: 10000 childid: 10000
id:197 parentid: 10001 childid: 10000 (new parent)
id:198 parentid: 10001 childid: 10001 (first child)
id:199 parentid: 10001 childid: 10002 (second child)
id:200 parentid: 10001 childid: 10003 (third child)
id:2 parentid: 10002 childid: 10000 (new parent)
... and so on
Your help is appreciated.
Edit: Code is below for what I am trying to do
<script type="text/javascript">
$(document).ready(
function()
{
var updateOutput = function(e)
{
var list = e.length ? e : $(e.target),
output = list.data('output');
if (window.JSON) {
output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
} else {
output.val('JSON browser support required for this demo.');
}
};
//this is where i need help
var postOutline = function(output){
$.post("something.cfc", {
method: 'getoutline',
output: output
});
};
// activate Nestable for list 1
$('#nestable3').nestable({
group: 1
})
// .on('change', updateOutput);
.on('change', postOutline);
// output initial serialised data
updateOutput($('#nestable3').data('output', $('#nestable-output')));
}
);
</script>