前端关系图谱插件_js前端使用jOrgChart插件实现组织架构图的展示
一、说明
(1)通过后台查询数据库,生成树形数组结构,返回到前台。
(2)需要引入的js插件和css文件:
①jquery.jOrgChart.css
②jquery.min.js
③jquery.jOrgChart.js
(3)使用jOrgChart插件,根据返回的数据将其子节点加入到相应的
中。
首先,我们的数据表应该要有 id(节点),pid(父节点的id),name的字段,
那么我们要把这个数组转为树形数组结构,即将各个元素放在 pid 父类元素的 childrens字段中,下面就是简单生成树形数组的代码。至于展示出来的样式,可以在html页面中添加自定义样式覆盖它之前的样式。
注意:
后台返回的数据格式必须如下,其中id,pid字段为必须要有。childrens字段也为必须的,不过字段名可以自己定义,name字段是根据自己业务需求的字段,在这里以name字段作为要显示的文本内容:
{
"data": [{
"id": 1,
"name": "企业主体信用得分",
"pid": null,
"childrens": [
{
"id": 2,
"name": "企业素质",
"pid": 1,
"childrens": [
{
"id": 5,
"name": "基本信息",
"pid": 2,
"childrens": [
{
"id": 10,
"name": "企业主体信息识别",
"pid": 5,
"childrens": [
]
},
{
"id": 11,
"name": "企业持续注册时间",
"pid": 5,
"childrens": [
]
},
{
"id": 12,
"name": "注册资本",
"pid": 5,
"childrens": [
]
}
]
},
{
"id": 6,
"name": "管理认证",
"pid": 2,
"childrens": [
{
"id": 13,
"name": "国际性管理认证",
"pid": 6,
"childrens": [
]
}
]
}
]
},
{
"id": 3,
"name": "履约记录",
"pid": 1,
"childrens": [
{
"id": 7,
"name": "税务执行情况",
"pid": 3,
"childrens": [
{
"id": 14,
"name": "是否按时缴纳税款",
"pid": 7,
"childrens": [
]
}
]
},
{
"id": 8,
"name": "网贷情况",
"pid": 3,
"childrens": [
{
"id": 15,
"name": "网贷逾期",
"pid": 8,
"childrens": [
]
}
]
}
]
},
{
"id": 4,
"name": "公共监督",
"pid": 1,
"childrens": [
{
"id": 9,
"name": "行政处罚",
"pid": 4,
"childrens": [
{
"id": 16,
"name": "处罚信息",
"pid": 9,
"childrens": [
]
}
]
}
]
}
]
}
]
}
二、实例:
1、json文件(test.json)(即后台接口返回的json格式的数据)
{
"data": [{
"id": 1,
"name": "企业主体信用得分",
"pid": null,
"childrens": [
{
"id": 2,
"name": "企业素质",
"pid": 1,
"childrens": [
{
"id": 5,
"name": "基本信息",
"pid": 2,
"childrens": [
{
"id": 10,
"name": "企业主体信息识别",
"pid": 5,
"childrens": [
]
},
{
"id": 11,
"name": "企业持续注册时间",
"pid": 5,
"childrens": [
]
},
{
"id": 12,
"name": "注册资本",
"pid": 5,
"childrens": [
]
}
]
},
{
"id": 6,
"name": "管理认证",
"pid": 2,
"childrens": [
{
"id": 13,
"name": "国际性管理认证",
"pid": 6,
"childrens": [
]
}
]
}
]
},
{
"id": 3,
"name": "履约记录",
"pid": 1,
"childrens": [
{
"id": 7,
"name": "税务执行情况",
"pid": 3,
"childrens": [
{
"id": 14,
"name": "是否按时缴纳税款",
"pid": 7,
"childrens": [
]
}
]
},
{
"id": 8,
"name": "网贷情况",
"pid": 3,
"childrens": [
{
"id": 15,
"name": "网贷逾期",
"pid": 8,
"childrens": [
]
}
]
}
]
},
{
"id": 4,
"name": "公共监督",
"pid": 1,
"childrens": [
{
"id": 9,
"name": "行政处罚",
"pid": 4,
"childrens": [
{
"id": 16,
"name": "处罚信息",
"pid": 9,
"childrens": [
]
}
]
}
]
}
]
}
]
}
2、html页面(test.html)
jOrgChart异步加载
a {
text-decoration: none;
color: #fff;
font-size: 12px;
}
.jOrgChart .node {
width: 120px;
height: 50px;
line-height: 50px;
border-radius: 4px;
margin: 0 8px;
}
$(function(){
//数据返回
$.ajax({
url: "test.json",
type: 'GET',
dataType: 'JSON',
data: {action: 'org_select'},
success: function(result){
var showlist = $("
showall(result.data, showlist);
$("#jOrgChart").append(showlist);
$("#org").jOrgChart( {
chartElement : '#jOrgChart',//指定在某个dom生成jorgchart
dragAndDrop : false //设置是否可拖动
});
}
});
});
function showall(menu_list, parent) {
$.each(menu_list, function(index, val) {
if(val.childrens.length > 0){
var li = $("
");
li.append(""+val.name+"").append("
//递归显示
showall(val.childrens, $(li).children().eq(1));
}else{
$("
").append(""+val.name+"").appendTo(parent);
}
});
}
Tp3admin的html代码
{extend name='admin@public/content'}
{block name="content"}
jquery组织架构插件-jOrgChart.js | jQuery特效|手机微信网站特效| 网页特效库
jQuery(document).ready(function() {
$("#org").jOrgChart({
chartElement : '#chart',
dragAndDrop : true
});
});
$(function(){
//数据返回
$.ajax({
url: '{:url("$classuri/return_json")}',
type: 'GET',
dataType: 'JSON',
data: {action: 'org_select'},
success: function(result){
var showlist = $("
console.log(result.data);
showall(result.data, showlist);
$("#jOrgChart").append(showlist);
$("#org").jOrgChart( {
chartElement : '#jOrgChart',//指定在某个dom生成jorgchart
dragAndDrop : false //设置是否可拖动
});
}
});
});
function showall(menu_list, parent) {
$.each(menu_list, function(index, val) {
if(val.childrens.length > 0){
var li = $("
");
li.append(""+val.id+val.user_name+"").append("
//递归显示
showall(val.childrens, $(li).children().eq(1));
}else{
$("
").append(""+val.id+val.user_name+"").appendTo(parent);
}
});
}
前端关系图谱插件_js前端使用jOrgChart插件实现组织架构图的展示相关推荐
- 组织架构图实现——jOrgChart的使用
最近公司需要做一个组织架构图,具体的功能如下: 我这边是做了横向和纵向两种展示方式: 目前这个还不是最终定稿,先不管了,光做这些就花了我好几天的时间了.jq操作dom我已经忘光了.. 步骤1:百度检索 ...
- html组织架构插件,jQuery组织架构图插件okrTree.js
插件描述:jQuery组织架构图支持拖拽节点,支持插入标记节点,分支节点 更新时间:2021-03-02 23:52:07 更新说明: 1. 修改默认主题, 2. 添加自定义主题接口var s = $ ...
- 前端关系图谱插件_智游告诉你,前端开发应该学什么?
今天接到一个咨询: 对话中这位同学提到的技能图谱,应该类似于这个: 相信大多数准备或者已经在学习前端开发的同学,都看到过或者正在按照这个类似的技能树学习. 这种技能图谱,通常是把关于前端的所有技术都罗 ...
- java代码借助插件生成组织架构图并实现导出功能
先说一下需求,前几天产品提出了一个很(恶)好(心)的需求,将组织机构生成架构图并且能导出,数据如下: 下面是架构图 根据数据和架构图可以看出来,其实就是有父子关系的数据而已,因为是Java项目且使用的 ...
- extjs实现组织架构图_如何画好一张架构图?(内含知识图谱)
什么是架构图? 如何画好一张架构图,要做好这件事情首先要回答的就是什么是架构图.我们日常工作中经常能看到各种各样的架构图,而且经常会发现大家对架构图的理解各有侧重.深入追究到这个问题,可能一下子还很难 ...
- 使用jOrgChart插件生成组织结构图
1.首先是下载js包,为了样式展示好看,在js包里有个bootstrap.min.css 下载地址https://download.csdn.net/download/weixin_38644118/ ...
- 使用jOrgChart插件, 异步加载生成组织架构图
项目要做组织架构图,要把它做成自上而下的树形结构,于是决定 (1)通过后台查询数据库,生成树形数组结构,返回到前台. (2)使用jOrgChart插件,根据返回的数据将其子节点加入到相应的<li ...
- 知识图谱前端插件_前端学习曲线原来越陡,说说我的学习经历
初学前端时,基本就是三大件:HTML+CSS+JavaScript,结合万能的jQuery就可以搭建出功能丰富.易于维护(自己感觉)的前端网站.进阶一下就是自己基于jQuery写一写插件,看着自己写的 ...
- 泛前端知识图谱(Web/iOS/Android/RN)
泛前端知识图谱(Web/iOS/Android/RN) 从属于笔者的程序员成长道路上的阅读学习资料工具集锦系列,主要是对于笔者这几年在前端开发中总结出来的知识点的归集与整理,也是笔者的笔记排布目录结构 ...
最新文章
- zendserver的版本是怎么回事?免费版哪里去了?
- 11个问题助你彻底搞懂工业互联网
- Application summary please elaborate on how you plan to use our API
- php中的header头,PHP中常用的header头部定义
- 在windows下使用llvm+clang
- 08年美国最值得信赖20大公司排行 谷歌落榜
- webpack使用和踩过的坑
- tomcat java 参数乱码_javaweb乱码(tomcat服务器)
- Java 解决跨域问题
- webform中提交按钮同时执行更新和插入操作_软件测试中的功能测试点(三)
- PCL_PCLVisualizer在多线程中的使用问题(viewer spinOnce crash)
- 用大前端技术实现的一款仿Boss直聘app(已开源)
- Linux内核移植操作步骤
- K3CLOUD业务系统编码规则设置
- 软件测试书单/书籍推荐(整理更新中)
- 关键信息基础设施网络风险地图
- 云音乐计算机等科目英文,音乐英文术语
- 送给python初学者在简单编程练习题中的小技巧
- python图片转黑白_Python 批量转化彩色图片为黑白图片
- 【软件测试】04 -- 软件测试与软件开发