使用方法(js代碼)
<script>
layui.config({
base: '../../../layui_exts/' //配置 layui 第三方擴展組件存放的基礎目錄
}).extend({
protree: 'proTree/protree'
}).use(['protree'], function(){
var protree = layui.protree;
//后臺傳入的 標題列表
var arr = [{
id: 1,
name: "一級標題",
pid: 0
}, {
id: 2,
name: "二級標題",
pid: 0
}, {
id: 3,
name: "2.1級標題",
pid: 2
}, {
id: 4,
name: "2.2級標題",
pid: 2
}, {
id: 5,
name: "1.1級標題",
pid: 1
}, {
id: 6,
name: "1.2級標題",
pid: 1
}, {
id: 7,
name: "1.21級標題",
pid: 6
}, {
id: 8,
name: "三級標題",
pid: 0
}, {
id: 9,
name: "1.22級標題",
pid: 6
}, {
id: 10,
name: "1.221級標題",
pid: 9
}, {
id: 11,
name: "1.2211級標題",
pid: 10
}, {
id: 12,
name: "1.2212級標題",
pid: 10
}
];
//執(zhí)行示例
protree.init('.innerUl',{
arr: arr,
close:true,
simIcon: "fa fa-file-o",//單個標題字體圖標 不傳默認glyphicon-file
mouIconOpen: "fa fa-folder-open-o",//含多個標題的打開字體圖標 不傳默認glyphicon-folder-open
mouIconClose:"fa fa-folder-o",//含多個標題的關(guān)閉的字體圖標 不傳默認glyphicon-folder-close
callback: function(id,name) {
alert("你選擇的id是" + id + ",名字是" + name);
}
});
});
</script>