鍍金池/ 問答/PHP  C++  HTML/ RBAC權(quán)限的遞歸遍歷,在ul標(biāo)簽里面,如何有層級(jí)關(guān)系

RBAC權(quán)限的遞歸遍歷,在ul標(biāo)簽里面,如何有層級(jí)關(guān)系

<div class="form-group">
                          <label class="col-sm-3 control-label">權(quán)限列表:</label>
                          <div class="col-sm-8">
                              <volist name="data_pri" id="vo"  >
                                  <ul class="checktree">
                                      <li>
                                          <input id="administration" type="checkbox" /><label for="administration">{$vo.pri_name}</label>
                                          <ul>
                                              <volist name="data_pri1" id="vo1"  >
                                              <li>
                                                  <if condition="$vo.id == $vo1.parent_id">
                                                  <input id="president" type="checkbox" /><label for="president">{$vo1.pri_name}</label>
                                                  </if>
                                                  <ul>
                                                      <li>
                                                          <input  type="checkbox" /><label for="manager1">添加商品</label>
                                                          <input  type="checkbox" /><label for="manager1">編輯商品</label>
                                                          <input  type="checkbox" /><label for="manager1">刪除商品</label>
                                                      </li>

                                                  </ul>
                                              </li>
                                              </volist>
                                          </ul>
                                      </li>
                                  </ul>
                              </volist>
                          </div>
                      </div>                     
 public function add_list()
    {

        $model = D('Privilege');
        //頂級(jí)分類
        $where="parent_id=0";
        $data_pri=$model->where($where)->select();

        //一級(jí)分類
        $where="level=1";
        $data_pri1=$model->where($where)->select();

        //二級(jí)分類
        $where="level=2";
        $data_pri2=$model->where($where)->select();


        $data = $model->search();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
            'data_pri'=>$data_pri,
            'data_pri1'=>$data_pri1,
            'data_pri2'=>$data_pri2
        ));

        // 設(shè)置頁(yè)面中的信息
        $this->assign(array(
            '_page_title' => '列表',
            '_page_btn_name' => '添加',
            '_page_btn_link' => U('add'),
        ));
        $this->display();
    }

圖片描述

以下是我的樣式

 <script>
        (function($){
            $.fn.checktree = function(){
                $(':checkbox').on('click', function (event){
                    event.stopPropagation();
                    var clk_checkbox = $(this),
                            chk_state = clk_checkbox.is(':checked'),
                            parent_li = clk_checkbox.closest('li'),
                            parent_uls = parent_li.parents('ul');
                    parent_li.find(':checkbox').prop('checked', chk_state);
                    parent_uls.each(function(){
                        parent_ul = $(this);
                        parent_state = (parent_ul.find(':checkbox').length == parent_ul.find(':checked').length);
                        parent_ul.siblings(':checkbox').prop('checked', parent_state);
                    });
                });
            };
        }(jQuery));
    </script>
    <style>
        body{
            width: 1100px;
            margin: 0 auto;
        }
        ul{
            list-style-type: none;
            margin: 3px;
        }
        ul.checktree li:before{
            height: 1em;
            width: 12px;
            border-bottom: 1px dashed;
            content: "";
            display: inline-block;
            top: -0.3em;
        }
        ul.checktree li{
            border-left: 1px dashed;
        }
        ul.checktree li:last-child:before {
            border-left: 1px dashed;
        }
        ul.checktree li:last-child{
            border-left: none;
        }
    </style>

圖片描述

我運(yùn)行是在thinkphp3.2.3版本下的,能否大伙能幫我遍歷的時(shí)候,我哪里出問題了

回答
編輯回答
亮瞎她

顯示的時(shí)候在 pri_name 前面添加 level個(gè)空格或者其它符號(hào) 就可以了

2018年8月12日 05:02