加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

thinkphp5 3级分类列表

发布时间:2020-12-14 13:57:52 所属栏目:大数据 来源:网络整理
导读:public function buildList($parent_id = 0,$level = 1) { $list = []; foreach ( $this->data as $key => $val ) { if ( $val['parent_id'] == $parent_id ) { $v['id'] = $val['id']; $v['parent_id'] = $val['parent_id']; $v['name'] = $val['name']; $v

public function buildList($parent_id = 0,$level = 1) {

$list = [];

foreach ( $this->data as $key => $val ) {

if ( $val['parent_id'] == $parent_id ) {

$v['id'] = $val['id'];

$v['parent_id'] = $val['parent_id'];

$v['name'] = $val['name'];

$v['module'] = $val['module'];

$v['filename'] = $val['filename'];

$v['icon'] = $val['icon'];

$v['is_show'] = $val['is_show'];

$v['sort'] = $val['sort'];

$v['level'] = $level;

$children = $this->buildList($v['id'],$level + 1);

if(empty($children)) {

$v['has_children'] = false;

} else {

$v['has_children'] = true;

}

$list[] = $v;

$list = array_merge($list,$children);

}

}

return $list;

}

css:?

.taxons-list {

border-right: 1px solid #f3f3f3;

border-bottom: 1px solid #f3f3f3;

}

.taxons-list li {

height: 45px;

line-height: 45px;

border-left: 1px solid #f3f3f3;

border-top: 1px solid #f3f3f3;

}

.taxons-list li a {

font-size: 14px;

}

.taxons-list .taxon-no {

width: 5%;

}

.taxons-list .taxon-name {

width: 50%;

}

.taxons-list .taxon-name img {

vertical-align: middle;

cursor: pointer;

}

.taxons-list .taxon-name .line-verticle {

display: block;

width: 15px;

height: 40px;

position: relative;

float: left;

}

.taxons-list .taxon-name .line-verticle:before {

content: '';

position: absolute;

top: 0;

left: 0;

width: 1px;

height: 25px;

background: #dddddd;

}

.taxons-list .taxon-name .line-verticle:after {

content: '';

position: absolute;

top: 25px;

left: 0;

width: 15px;

height: 1px;

background: #dddddd;

}

.taxons-list .taxon-name .line-more {

width: 30px;

}

.taxons-list .taxon-name .line-more:before {

content: '';

position: absolute;

top: 0;

left: 0;

width: 1px;

height: 25px;

background: #dddddd;

}

.taxons-list .taxon-name .line-more:after {

content: '';

position: absolute;

top: 25px;

left: 0;

width: 30px;

height: 1px;

background: #dddddd;

}

.taxons-list .taxon-module {

width: 10%;

}

.taxons-list .taxon-show {

width: 10%;

}

.taxons-list .taxon-sort {

width: 10%;

}

.taxons-list .taxon-operate {

width: 10%;

}

.taxons-list .pull-left {

border-right: 1px solid #d9d9d9;

padding-left: 5px;

}

.taxons-list .taxon-header {

background: #f3f3f3;

}

.taxons-list .taxon-hide {

display: none;

}

html:

  • {volist name="list" id="vo"}

    {if condition="$vo['level'] eq 1"}

  • {else /}

  • {/if}

    {if condition="$vo['has_children'] eq true"}

    {else /}

    {/if}

    {if condition="$vo['level'] eq 2"}

    {elseif condition="$vo['level'] eq 3"}

    {/if}

    {$vo.name}

  • {/volist}

js:

$(".taxons-list li").each(function() {

$(this).click(function() {

// 只考虑3级

var id = $(this).attr('data-id');

var next_node = $('.parent_'+id);

var icon = $(this).find('.taxon-name img');

if (next_node.hasClass('taxon-hide')) {

icon.attr('src','no_children.gif');

next_node.removeClass('taxon-hide');

} else {

if (next_node.length != 0) {

icon.attr('src','has_children.gif');

}

next_node.addClass('taxon-hide');

// 如果还有第三级

var next_id = next_node.attr('data-id');

var next_next_node = $('.parent_'+next_id);

if(next_next_node.length != 0) {

next_node.find('.taxon-name img').attr('src','has_children.gif');

next_next_node.addClass('taxon-hide');

}

}

})

})

效果:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读