導航:首頁 > 編程語言 > js下拉樹形

js下拉樹形

發布時間:2024-09-29 23:21:55

① 求angularjs select2寫的下拉樹形列表源碼,類似於附件圖片里的結構

使用group by 去進行分組。這個像sql語句一樣的回
<select ng-model="selected" ng-options="(m.proctColor + ' - ' + m.proctName) group by m.mainCategory for m in model">
<option value="">-- 請選擇答 --</option>
</select>

② Vue.js怎樣把遞歸組件構建為樹形菜單

Vue.js 遞歸組件實現樹形菜單
main.js 作為入口:

import Vue from 'vue'import main from './components/main.vue' new Vue({ el: '#app', render: h => h(main)})

它引入了一個組件 main.vue:

<template> <div> <my-tree :data="theData" :name="menuName" :loading="loading" @="getSubMenu"></my-tree> </div></template> <script>const myData = [ { id: '1', menuName: '基礎管理', menuCode: '10' }, { id: '2', menuName: '商品管理', menuCode: '' }, { id: '3', menuName: '訂單管理', menuCode: '30', children: [ { menuName: '訂單列表', menuCode: '31' }, { menuName: '退貨列表', menuCode: '32', children: [] } ] }, { id: '4', menuName: '商家管理', menuCode: '', children: [] }]; const subMenuData1 = { parentId: '1', children: [ { menuName: '用戶管理', menuCode: '11' }, { id: '12', menuName: '角色管理', menuCode: '12', children: [ { menuName: '管理員', menuCode: '121' }, { menuName: 'CEO', menuCode: '122' }, { menuName: 'CFO', menuCode: '123' }, { menuName: 'COO', menuCode: '124' }, { menuName: '普通人', menuCode: '124' } ] }, { menuName: '許可權管理', menuCode: '13' } ]}; const subMenuData2 = { parentId: '2', children: [ { menuName: '商品一', menuCode: '21' }, { id: '22', menuName: '商品二', menuCode: '22', children: [ { menuName: '子類商品1', menuCode: '221' }, { menuName: '子類商品2', menuCode: '222' } ] } ]}; import myTree from './common/treeMenu.vue'export default { components: { myTree }, data () { return { theData: myData, menuName: 'menuName', // 顯示菜單名稱的屬性 loading: false } }, methods: { getSubMenu (menuItem, callback) { this.loading = true; if (menuItem.id === subMenuData1.parentId) { this.loading = false; menuItem.children = subMenuData1.children; callback(menuItem.children); } setTimeout(() => { if (menuItem.id === subMenuData2.parentId) { this.loading = false; menuItem.children = subMenuData2.children; callback(menuItem.children); } }, 2000); } }}</script>

subMenuData1, subMenuData2 存放子菜單數據,可以從伺服器獲取,以實現動態載入。
文件引入了樹形組件 treeMenu.vue:
<template> <ul class="tree-menu"> <li v-for="(item, index) in data"> <span @click="toggle(item, index)"> <i :class="['icon', item.children && item.children.length ? folderIconList[index] : 'file-text', loading ? loadingIconList[index] : '']"></i> {{ item[name] || item.menuName }} </span> <tree-menu v-if="scope[index]" :data="item.children"></tree-menu> </li> </ul></template> <script>export default { name: 'treeMenu', props: { data: Array, name: String, loading: Boolean }, data () { return { folderIconList: [], loadingIconList: [], scope: {} } }, created () { this.data.forEach((item, index) => { if (item.children && item.children.length) { this.folderIconList[index] = 'folder'; } }); }, methods: { doTask (index) { this.$set(this.scope, index, !this.scope[index]); this.folderIconList[index] = this.scope[index] ? 'folder-open' : 'folder'; }, toggle (item, index) { this.loadingIconList = []; if (item.children && item.children.length) { this.doTask(index); } else { this.loadingIconList[index] = 'loading'; this.$emit('getSubMenu', item, (subMenuList) => { if (subMenuList && subMenuList.length) { this.doTask(index); } }); } } }}</script> <style scoped>.tree-menu { list-style: none;}.tree-menu li { line-height: 2;}.tree-menu li span { cursor: default;}.icon { display: inline-block; width: 15px; height: 15px; background-repeat: no-repeat; vertical-align: -2px;}.icon.folder { background-image: url(/src/assets/folder.png);}.icon.folder-open { background-image: url(/src/assets/folder-open.png);}.icon.file-text { background-image: url(/src/assets/file-text.png);}.icon.loading { background-image: url(/src/assets/loading.gif); background-size: 15px;}</style>

java web : jstree和ztree的關系是什麼

都是 js 的樹形控制項, 一個是老外寫的,一個是國人寫的

④ javascript實現動態載入樹形菜單(tree),

頁面既然得到抄從服務襲器傳過來的json數據之後,還要轉換為Object
比如,伺服器組裝好的json數據:
{
id:'001',
nodeMsg:'節點1'
}
這個是ajax成功之後的回調
function(xhr){
var o = eval('(' + xhr.responseText + ')');
alert(o.id + ':' + o.nodeMsg);
}

⑤ 如何用javascript 實現樹形結構菜單,可伸縮,有節點。請高手指教!

這個應該適合你:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="http://123.jialulu.com/css/tree.css" type="text/css" />
<style type="text/css">
a {text-decoration:none;}
a,a:visited {color:#000;background:inherit;}
body {margin:0;padding:20px;font:12px tahoma,宋體,sans-serif;}
dt {font-size:22px;font-weight:bold;margin:0 0 0 15px;}
dd {margin:0 0 0 15px;}
h4 {margin:0;padding:0;font-size:18px;text-align:center;}
p {margin:0;padding:0 0 0 18px;}
p a,p a:visited {color:#00f;background:inherit;}
/*Temp CSS for View Demo*/
#CNLTreeMenu {float:left;width:249px;border:1px solid #99BEEF;background:#D2E4FC;color:inherit;margin:3px;padding:3px;}
#CNLTreeMenu {padding-bottom:15px;}
</style>
<title>無限級樹形菜單</title>
</head>
<body>
<div class="CNLTreeMenu" id="CNLTreeMenu">
<h4>CNL Tree Menu1</h4>
<p><a id="AllOpen" href="#" onClick="MyCNLTreeMenu.SetNodes(0);Hd(this);Sw('AllClose');">全部展開</a><a id="AllClose" href="#" onClick="MyCNLTreeMenu.SetNodes(1);Hd(this);Sw('AllOpen');" style="display:none;">全部折疊</a></p>
<ul>
<li class="Opened"><a href="http://www.jialulu.com">Zzsky.Cn</a>
<ul>
<li><a href="#1">技術區</a>
<ul>
<li><a href="#">網頁技術</a>
<ul>
<li class="Child"><a href="#">JavaScript</a></li>
<!--Child Node-->
<li class="Child"><a href="#">HTML/XHTML/CSS</a></li>
<li class="Child"><a href="#">Ajax</a></li>
<li class="Child"><a href="#">網頁製作工具</a></li>
<li class="Child"><a href="#">設計/圖形</a></li>
<li class="Child"><a href="#">Flash/多媒體</a></li>
<li class="Child"><a href="#">VML/Web3D</a></li>
</ul>
</li>
<!--Sub Node 3-->
<li><a href="#">Web編程</a>
<ul>
<li class="Child"><a href="#">Java</a></li>
<!--Child Node-->
<li class="Child"><a href="#">.Net</a></li>
<li class="Child"><a href="#">ASP/VBScript</a></li>
<li class="Child"><a href="#">PHP</a></li>
<li class="Child"><a href="#">Perl/Python</a></li>
<li class="Child"><a href="#">Web綜合/開源</a></li>
</ul>
</li>
<!--Sub Node 3-->
<li><a href="#">資料庫</a>
<ul>
<li class="Child"><a href="#">Access/SQLServer</a></li>
<!--Child Node-->
<li class="Child"><a href="#">MySQL/PostgreSQL</a></li>
<li class="Child"><a href="#">Oracle/DB2/Sybase</a></li>
</ul>
</li>
<!--Sub Node 3-->
<li><a href="#">伺服器</a>
<ul>
<li class="Child"><a href="#">Windows/IIS</a></li>
<!--Child Node-->
<li class="Child"><a href="#">Unix/Linux/Apache</a></li>
<li class="Child"><a href="#">應用伺服器</a></li>
</ul>
</li>
<!--Sub Node 3-->
</ul>
</li>
<!--Sub Node 2-->
<li><a href="#1">二級目錄</a>
<ul>
<li><a href="#">三級目錄</a>
<ul>
<li><a href="#">四級目錄</a>
<ul>
<li><a href="#">五級目錄</a>
<ul>
<li><a href="#">......</a>
<ul>
<li><a href="#">第n級目錄</a>
<ul>
<li class="Child"><a href="#">葉結點1</a></li>
<!--Child Node-->
<li class="Child"><a href="#">葉結點2</a></li>
<li class="Child"><a href="#">葉結點3</a></li>
</ul>
</li>
<!--Sub Node n -->
</ul>
</li>
<!--Sub Node 6 -->
</ul>
</li>
<!--Sub Node 5 -->
</ul>
</li>
<!--Sub Node 4-->
</ul>
</li>
<!--Sub Node 3-->
</ul>
</li>
<!--Sub Node 2-->
<li><a href="#1">二級目錄</a>
<ul>
<li><a href="#">三級目錄</a>
<ul>
<li><a href="#">四級目錄</a>
<ul>
<li><a href="#">五級目錄</a>
<ul>
<li><a href="#">......</a>
<ul>
<li><a href="#">第n級目錄</a>
<ul>
<li class="Child"><a href="#">葉結點1</a></li>
<!--Child Node-->
<li class="Child"><a href="#">葉結點2</a></li>
<li class="Child"><a href="#">葉結點3</a></li>
</ul>
</li>
<!--Sub Node n -->
</ul>
</li>
<!--Sub Node 6 -->
</ul>
</li>
<!--Sub Node 5 -->
</ul>
</li>
<!--Sub Node 4-->
</ul>
</li>
<!--Sub Node 3-->
</ul>
</li>
<!--Sub Node 2-->
</ul>
</li>
<!--Sub Node 1 -->
</ul>
</div>
<!-- CNLTreeMenu -->
<!--CNLTreeMenu1 End!-->
<script type="text/javascript">
<!--
function Ob(o){
var o=document.getElementById(o)?document.getElementById(o):o;
return o;
}
function Hd(o){
Ob(o).style.display="none";
}
function Sw(o){
Ob(o).style.display="";
}
function ExCls(o,a,b,n){
var o=Ob(o);
for(i=0;i<n;i++){o=o.parentNode;}
o.className=o.className==a?b:a;
}
function CNLTreeMenu(id,TagName0){
this.id=id;
this.TagName0=TagName0==""?"li":TagName0;
this.AllNodes = Ob(this.id).getElementsByTagName(TagName0);
this.InitCss = function (ClassName0,ClassName1,ClassName2,ImgUrl){
this.ClassName0=ClassName0;
this.ClassName1=ClassName1;
this.ClassName2=ClassName2;
this.ImgUrl=ImgUrl || "http://123.jialulu.com/images/s.gif";
this.ImgBlankA ="<img src=\""+this.ImgUrl+"\" class=\"s\" onclick=\"ExCls(this,'"+ClassName0+"','"+ClassName1+"',1);\" alt=\"展開/折疊\" />";
this.ImgBlankB ="<img src=\""+this.ImgUrl+"\" class=\"s\" />";
for (i=0;i<this.AllNodes.length;i++ ){
this.AllNodes[i].className==""?this.AllNodes[i].className=ClassName1:"";
this.AllNodes[i].innerHTML=(this.AllNodes[i].className==ClassName2?this.ImgBlankB:this.ImgBlankA)+this.AllNodes[i].innerHTML;
}
}
this.SetNodes = function (n){
var sClsName=n==0?this.ClassName0:this.ClassName1;
for (i=0;i<this.AllNodes.length;i++ ){
this.AllNodes[i].className==this.ClassName2?"":this.AllNodes[i].className=sClsName;
}
}
}
var MyCNLTreeMenu=new CNLTreeMenu("CNLTreeMenu","li");
MyCNLTreeMenu.InitCss("Opened","Closed","Child","http://123.jialulu.com/images/s.gif");
-->
</script>
</body>
</html>

閱讀全文

與js下拉樹形相關的資料

熱點內容
ps入門必備文件 瀏覽:348
以前的相親網站怎麼沒有了 瀏覽:15
蘋果6耳機聽歌有滋滋聲 瀏覽:768
怎麼徹底刪除linux文件 瀏覽:379
編程中字體的顏色是什麼意思 瀏覽:534
網站關鍵詞多少個字元 瀏覽:917
匯川am系列用什麼編程 瀏覽:41
筆記本win10我的電腦在哪裡打開攝像頭 瀏覽:827
醫院單位基本工資去哪個app查詢 瀏覽:18
css源碼應該用什麼文件 瀏覽:915
編程ts是什麼意思呢 瀏覽:509
c盤cad佔用空間的文件 瀏覽:89
不銹鋼大小頭模具如何編程 瀏覽:972
什麼格式的配置文件比較主流 瀏覽:984
增加目錄word 瀏覽:5
提取不相鄰兩列數據如何做圖表 瀏覽:45
r9s支持的網路制式 瀏覽:633
什麼是提交事務的編程 瀏覽:237
win10打字卡住 瀏覽:774
linux普通用戶關機 瀏覽:114

友情鏈接