jQuery技术

Laravel 5 中基于 jQuery 实现分层级的类目树结构实例教程 Larav(2)

字号+ 作者:H5之家 来源:H5之家 2017-04-27 08:01 我要评论( )

然后是resources/views/manageChild.blade.php: ul@foreach($childsas$child)li{{$child-title}}@if(count($child-childs))@include('manageChild',['childs'=$child-childs])@endif/li@endforeach/ul 第六步:添

然后是resources/views/manageChild.blade.php:

<ul> @foreach($childsas$child) <li> {{$child->title}} @if(count($child->childs)) @include('manageChild',['childs'=>$child->childs]) @endif </li> @endforeach </ul>

第六步:添加CSS和JS文件

最后一步,我们来添加视图文件所需要的CSS和JS文件。

public/css/treeview.css:

.tree,.treeul{ margin:0; padding:0; list-style:none } .treeul{ margin-left:1em; position:relative } .treeulul{ margin-left:.5em } .treeul:before{ content:""; display:block; width:0; position:absolute; top:0; bottom:0; left:0; border-left:1pxsolid } .treeli{ margin:0; padding:01em; line-height:2em; color:#369; font-weight:700; position:relative } .treeulli:before{ content:""; display:block; width:10px; height:0; border-top:1pxsolid; margin-top:-1px; position:absolute; top:1em; left:0 } .treeulli:last-child:before{ background:#fff; height:auto; top:1em; bottom:0 } .indicator{ margin-right:5px; } .treelia{ text-decoration:none; color:#369; } .treelibutton,.treelibutton:active,.treelibutton:focus{ text-decoration:none; color:#369; border:none; background:transparent; margin:0px0px0px0px; padding:0px0px0px0px; outline:0; }

public/js/treeview.js:

$.fn.extend({ treed:function(o){ varopenedClass='glyphicon-minus-sign'; varclosedClass='glyphicon-plus-sign'; if(typeofo!='undefined'){ if(typeofo.openedClass!='undefined'){ openedClass=o.openedClass; } if(typeofo.closedClass!='undefined'){ closedClass=o.closedClass; } }; /*initializeeachofthetoplevels*/ vartree=$(this); tree.addClass("tree"); tree.find('li').has("ul").each(function(){ varbranch=$(this); branch.prepend(""); branch.addClass('branch'); branch.on('click',function(e){ if(this==e.target){ varicon=$(this).children('i:first'); icon.toggleClass(openedClass+""+closedClass); $(this).children().children().toggle(); } }) branch.children().children().toggle(); }); /*fireeventfromthedynamicallyaddedicon*/ tree.find('.branch.indicator').each(function(){ $(this).on('click',function(){ $(this).closest('li').click(); }); }); /*fireeventtoopenbranchifthelicontainsananchorinsteadoftext*/ tree.find('.branch>a').each(function(){ $(this).on('click',function(e){ $(this).closest('li').click(); e.preventDefault(); }); }); /*fireeventtoopenbranchifthelicontainsabuttoninsteadoftext*/ tree.find('.branch>button').each(function(){ $(this).on('click',function(e){ $(this).closest('li').click(); e.preventDefault(); }); }); } }); /*初始化树状图*/ $('#tree1').treed();

好了,至此所有代码已经编写完成,你可以在浏览器中查看效果了。

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评
e