创建动态菜单项和子菜单项 [英] create dynamic menu item and submenus item

查看:133
本文介绍了创建动态菜单项和子菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是

我必须在数据库中创建ID,父ID,名称

这是我的数据库

hi my project is

i have to create id, parent id , Name in database

this is my database

id    Parentid   Name
---------------------
1       0         A
2       1         B
3       1         C
4       0         D
5       4         E
6       4         F
7       0         G



现在我应该得到输出为



now i should get output as

A    D     G
------------
B    E
C    F


如果我添加任何其他主菜单,它们将自动成为子菜单.

我用过json,我的代码是

这是我的查看页面
---------------------


if i add any more main menus are sub menus automatically it should take.

i have used json my code is

this is my view page
---------------------

script type="text/javascript">
    var url = '/home/get'
    $.ajax({ type: "get",
        url: url,
        datatype: "json",
        error: function (xhr, status, error) {
            alert(error);
        },
        success: function (json) {
            var g = json.st.length;
           // var h = json.r.length;
            alert("displaying values: " + g);
            var menu = new dhtmlXMenuObject("menuObj");
          //  menu.attachEvent("onTouch", menuTouch);
            {
                for (i = ((json.st.length) - 1); i >= 0; i--) {
                    alert("displayed data: " + json.st);
                    menu.addNewSibling(null, "a", json.st[i], false);
                    {
                        // if (json.st.id == json.st.Parentid)
                        if(json.r[i].id == json.r[i].Parentid)
                           // for (i = ((json.r.length) - 1); i >= 0; i++)
                            {
                                menu.addNewChild("a", 0, "new", json.r[i], false);
                            }
                            else
                            {
                                // menu.addNewSeparator("new");
                                menu.addNewChild("b", 0, "file", json.r[i], false);
                            }
                         alert("displaying data: " + json.r);
                    }
                }
        }
    });
</script>
</head>



但我要放下



but im getting out put

A    D     G
------------
B    
C    


我没有得到secong主菜单项

我无法从主菜单D G etccc中获得子菜单


所以朴素的建议是否有任何步骤要进行

谢谢


i am not getting the secong main menu item

i couldn''t able to get submenus from main menu D G etccc


so plaese suggest if there is any step to proceed

Thank you

推荐答案

.ajax({类型:" , 网址:url, 数据类型:" , 错误:功能(xhr,状态,错误){ 警报(错误); }, 成功:功能(json){ var g = json.st.length; // var h = json.r.length; alert(" + g); var 菜单= dhtmlXMenuObject(" menuObj"); // menu.attachEvent("onTouch",menuTouch); { for (i =(((json.st.length)- 1 ); i> = 0 ; i--){ alert(" + json.st); menu.addNewSibling(" ,json.st [i], false ); { // 如果(json.st.id == json.st.Parentid) 如果(json.r [i] .id == json.r [i] .Parentid) // for(i =((json.r.length)-1); i> = 0; i ++) { menu.addNewChild(" 0 " ,json.r [i], false ); } 其他 { // menu.addNewSeparator("new"); menu.addNewChild(" 0 " ,json.r [i], false ); } alert(" + json.r); } } } }); </script> </ >
.ajax({ type: "get", url: url, datatype: "json", error: function (xhr, status, error) { alert(error); }, success: function (json) { var g = json.st.length; // var h = json.r.length; alert("displaying values: " + g); var menu = new dhtmlXMenuObject("menuObj"); // menu.attachEvent("onTouch", menuTouch); { for (i = ((json.st.length) - 1); i >= 0; i--) { alert("displayed data: " + json.st); menu.addNewSibling(null, "a", json.st[i], false); { // if (json.st.id == json.st.Parentid) if(json.r[i].id == json.r[i].Parentid) // for (i = ((json.r.length) - 1); i >= 0; i++) { menu.addNewChild("a", 0, "new", json.r[i], false); } else { // menu.addNewSeparator("new"); menu.addNewChild("b", 0, "file", json.r[i], false); } alert("displaying data: " + json.r); } } } }); </script> </head>



但我要放下



but im getting out put

A    D     G
------------
B    
C    


我没有得到secong主菜单项

我无法从主菜单D G etccc中获得子菜单


所以朴素的建议是否有任何步骤要进行

谢谢


i am not getting the secong main menu item

i couldn''t able to get submenus from main menu D G etccc


so plaese suggest if there is any step to proceed

Thank you


这篇关于创建动态菜单项和子菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆