General developer forum

how to create dynamic multi level dropdown in jquery

 
Picture of john kenley
how to create dynamic multi level dropdown in jquery
 

i have dynamic json structure as mentioned below, need to fill tree like in the html drop down dynamically. there may be sub level, sub sub level, grand sub level ....

[{"Key":"001","Record":{"PrefcatID":"001","parentid":"0","prefname":"org1"}},{"Key":"002","Record":{"PrefcatID":"002","parentid":"0","prefname":"org2"}},{"Key":"003","Record":{"PrefcatID":"003","parentid":"0","prefname":"org3"}},{"Key":"004","Record":{"PrefcatID":"004","parentid":"001","prefname":"suborg1"}},{"Key":"005","Record":{"PrefcatID":"005","parentid":"001","prefname":"suborg2"}},{"Key":"006","Record":{"PrefcatID":"006","parentid":"002","prefname":"suborg1"}},{"Key":"007","Record":{"PrefcatID":"007","parentid":"004","prefname":"subsuborg1"}}]


OrgID   OrgName        parentID
001    org1           0 -----th top
002    org2           0
003    org3           0
004    suborg1        001
005    suborg2       001
006    suborg1       002
007    subsuborg1    004 

like as above any number of levels need to be created

code which i tried but only upto one level, need to make it dynamic to grand levels ;( javascript code:

fun_filldropdown(data, 0, 0);
function fun_filldropdown(data)
{
    $.each(response, function(i, item) {

    if(item.Record.parentid == parentid )
    {
        console.log("parent-"+ item.Record.prefname);
    }
    $.each(response, function(j, subitem) {

        if(item.Record.PrefcatID == subitem.Record.parentid )
        {
            console.log("sub---"+ subitem.Record.prefname);

            //fun_filldropdown(response,item.Record.PrefcatID );
        }

    });



    });
}

can someone help me on doing this?

is this possible?????????


 
Average of ratings: -