doubaisui2526 2015-07-29 12:03
浏览 65

递归下拉菜单在Bootstrap Codeigniter上无法正确显示

I have issues displaying a dropdown menu generated by a recursive function using a database. The parents are shown correctly below the items, but not as nav items, but just as a basic list.

Here's the image with how it actually looks: enter image description here

And here's how it SHOULD look:

enter image description here

Some relevant code:

Model:

<?php
class New_menu_model extends CI_Model {
    function get_domains() {
        $result = $this->db->get ( 'domenii' );
        return $result->result_array();
    }
}
    function recursive($parent, $result) {

        $has_children = false;
        foreach ( $result as $key => $value ) {
            if ($value ['parent'] == $parent) {
                if ($has_children === false && $parent) {
                    $has_children = true;
                    echo '<ul>' . "
" ;
                }
                echo '<li>' . "
";
                echo '<a href="/menu/domenii/' . $value ['id_domeniu'] . '">' . $value ['nume_domeniu'] . '</a>' . " 
";
                echo "
";
                recursive ( $key + 1, $result );
                echo "</li>
";
            }
        }
        if ($has_children === true && $parent)
            echo "</ul>
";
    }

?>

View:

 <li class="dropdown"><?php echo recursive(0, $menu); ?></li>

Thanks!

  • 写回答

1条回答 默认 最新

  • dongzhe3171 2015-07-29 12:22
    关注

    It should be something like:

    <li class="dropdown">
    
         <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
              Dropdown <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
             <?php echo recursive(0, $menu); ?>
           </ul>
    </li>
    

    ...and check echo '<ul>' . " " ; , it could be echo '<ul class="dropdown-menu">' . " " ; so the code should be:

     <li class="dropdown">
    
             <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
                  Dropdown <span class="caret"></span>
                </a>
    
                 <?php echo recursive(0, $menu); ?>
    
        </li>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制