thinkphp5 父子栏目角色管理

发布时间:2020-08-10作者:小灵龙点击:70

问题描述:
     栏目管理的时候需要调用父子栏目,点击父栏目下方出现子栏目,便于管理角色权限。
解决办法:

php:

function getCat($tid = 0, $cat_type = 0, $use_type = 0, $all_cat = 1)
{
    static $n_list;
    $table='goods_cagory';
    if($cat_type == 1) $table='article_cateory';
    if($cat_type == 2) $table='admin_nu';
    $list = Db::name($table)->where('parent_id', $tid);
    if($use_type) $list = $list->where('is_show', '=', 1);
    $list = $list->order('sequence')->select();
    foreach ($list as $k => $v)
    {
        $n_list[] = $v;
        if($all_cat) getCat($v['id'],$cat_type);
    }
    return $n_list;
}

html:

      {volist name="list" id="list"}
            {eq name="$list.parent_id" value="0"}
              <tr>
                 <td>{$list.id}</td>   
                 <td>{$list.title} <a href="javascript:changetab('{$list.id}');">[<span id="span{$list.id}">+</span>]</a></td>
                 <input type="hidden" id="open{$list.id}" value="0">
              </tr>
              {else}
              <tr class="child{$list.parent_id}" style="display: none;">
                 <td>{$list.id}</td>   
                 <td>&emsp;└&ensp;{$list.title}</td>
              </tr>
           {/eq}

      {/volist}

       <script type="text/javascript">
        function changetab(id) {
            if($('#open'+id).val()==0){
             $('.child'+id).show();
             $('#open'+id).val(1);
             $('#span'+id).html('-');

            } else {
             $('.child'+id).hide();
             $('#open'+id).val(0);
             $('#span'+id).html('+');
            }
        };  
    </script>


标签: