Write a JS function to convert an array like this ...
arr_Menu_Driver = [
['USA','','','','',''],
['Russia','/countries?id=801','Moscow','','',''],
['Russia','/countries?id=801','St Petersburg','/cities?id=97','Nevsky
Prospekt','/streets?id=5'],
['UK','/countries?id=802','London','/cities?id=96', 'Oxford
Street','/streets?id=6'],
['UK','/countries?id=802','London','/cities?id=96','Piccadilly','/streets?id=7'],
['UK','/countries?id=802','Edinburgh','/cities?id=95','Princes Street','']
]
into a structure like this....
var MENU_ITEMS = [
{"popup":,'/streets?id=802'1, "popupoff":[0,0], "pos":[0,0],
"size":[20,70], "itemoff":[19,0], "leveloff":[10,59], "delay":500,
"style":STYLE},
{code:"USA",style:DISABLEDMENUELEMENT},
{code:"Russia",url:"/countries?id=801"
sub:[
{code:"Moscow",style:DISABLEDMENUELEMENT},
{code:"St Petersburg",url:"/cities?id=97"}
sub:[
{"itemoff":[21,0]},
{code:"Nevsky Prospekt", "url":"/streets?id=5"}
]},
]},
},
{code:"UK",url:"/countries?id=802"
sub:[
{code:"London",url:"/cities?id=96"
sub:[
{"itemoff":[21,0]},
{code:"Oxford Street", "url":"/streets?id=6"},
{code:"Piccadilly Circus", "url":"/streets?id=7"}
]},
{code:"Edinburgh",url:"/cities?id=95"}
sub:[
{"itemoff":[21,0]},
{code:"Princes Street", style:DISABLEDMENUELEMENT}
]},
]},
},
]
... the MENU_ITEMS structure is one used by CoolDev Menuing system
(see http://javascript.cooldev.com/doc/menu/ for details).
It's worth noting that where an element in the input array has no URL
this results in that menu element being 'disabled' in the sense that
(A) it has not child menu elements and (B) the attribute 'style' is
set to DISABLEDMENUELEMENT.
To start with it might make it easier to illustrate the requirement
with an input array that has no disabled elements so here goes with
one that is all enabled...
arr_Menu_Driver = [
['USA','/countries?id=800','New York','/cities?id=99','Fifth
Avenue','/streets?id=0'],
['USA','/countries?id=800','New York','/cities?id=99','Wall
Street','/streets?id=1'],
['USA','/countries?id=800','Washington
DC','/cities?id=999','Pennsylvania Avenue','/streets?id=2'],
['Russia','/countries?id=801','Moscow','/cities?id=98','Tverskaya
Ulitsa','/streets?id=3'],
['Russia','/countries?id=801','Moscow','/cities?id=98','Kuznetsky
Most','/streets?id=4'],
['Russia','/countries?id=801','St Petersburg','/cities?id=97','Nevsky
Prospekt','/streets?id=5'],
['UK','/countries?id=802','London','/cities?id=96', 'Oxford
Street','/streets?id=6'],
['UK','/countries?id=802','London','/cities?id=96','Piccadilly','/streets?id=7'],
['UK','/countries?id=802','Edinburgh','/cities?id=95','Princes
Street','/streets?id=8']
]
var MENU_ITEMS = [
{"popup":,'/streets?id=802'1, "popupoff":[0,0], "pos":[0,0],
"size":[20,70], "itemoff":[19,0], "leveloff":[10,59], "delay":500,
"style":STYLE},
{code:"USA",url:"/countries?id=800",
sub:[
{code:"New York",url:"/streets?id=99"
sub:[
{"itemoff":[21,0]},
{code:"Fifth Avenue", "url":"/streets?id=0"},
{code:"Wall Street", "url":"/streets?id=1"}
]},
{code:"Washington",url:"/streets?id=999"}
sub:[
{"itemoff":[21,0]},
{code:"Pennsylvania Avenue", "url":"/streets?id=0"}
]},
]},
{code:"Russia",url:"/countries?id=801"
sub:[
{code:"Moscow",url:"/cities?id=98"
sub:[
{"itemoff":[21,0]},
{code:"Tverskaya Ulitsa", "url":"/streets?id=3"},
{code:"Kuznetsky Most", "url":"/streets?id=4"}
]},
{code:"St Petersburg",url:"/cities?id=97"}
sub:[
{"itemoff":[21,0]},
{code:"Nevsky Prospekt", "url":"/streets?id=5"}
]},
]},
},
{code:"UK",url:"/countries?id=802"
sub:[
{code:"London",url:"/cities?id=96"
sub:[
{"itemoff":[21,0]},
{code:"Oxford Street", "url":"/streets?id=6"},
{code:"Piccadilly Circus", "url":"/streets?id=7"}
]},
{code:"Edinburgh",url:"/cities?id=95"}
sub:[
{"itemoff":[21,0]},
{code:"Princes Street", "url":"/streets?id=8"}
]},
]},
},
]
Please ask questions if this is not clear. |