Navigation using layui rendering here
Entity Class
private int id; //id private String dept_name; //Department name private int pid; //The superior department id private int sort_num; //Sort values private int create_id; //Create private String create_time; //Creation time private int modify_id; //Modify private String modify_time; //Last modified time private int is_del; // Whether to delete 0 Not deleted 1 Deleted private int status; //status private String remark; //remark private List<Dept> deptChild = new ArrayList<>(); //Department iteration
List<Dept> selectDeptForJsonMenu();
<resultMap type="" > <result column="id" property="id" javaType="" /> <result column="dept_name" property="dept_name" javaType="" /> <result column="sort_num" property="sort_num" javaType="" /> <result column="create_time" property="create_time" javaType="" /> <result column="modify_id" property="modify_id" javaType="" /> <result column="modify_time" property="modify_time" javaType="" /> <result column="is_del" property="is_del" javaType="" /> <result column="status" property="status" javaType="" /> <result column="remark" property="remark" javaType="" /> <collection column="id" property="deptChild" javaType="" select="selectDeptForJsonMenuChild"/> </resultMap> <!-- Query department menu tree --> <select resultMap="deptFirst"> SELECT * FROM sys_dept WHERE pid = 0 AND is_del = 0 ORDER BY sort_num </select> <select resultMap="deptFirst" parameterType=""> select * FROM sys_dept where pid = #{id} AND is_del = 0 ORDER BY sort_num </select>
public List<Dept> selectDeptForJsonMenu(){ return (); }
@RequestMapping(value = "selectDeptForJsonMenu",method={,}) @ResponseBody public List<Dept> selectDeptForJsonMenu(){ return (); }
html is introduced and the element module is loaded.
<div > </div>
$(function(){ $.ajax({ method:'post', url:getPath+"dept/selectDeptForJsonMenu", dataType:'json', success:function(data){ if( > 0){ var showlist = $('<ul class="layui-nav layui-nav-tree"></ul>'); showall(data, showlist); $("#leftMenu").html(showlist); }else{ $('#leftMenu').html('<span class="layui-btn layui-btn-primary" >Add</span>') ; } } }); //json is json data //parent is the final html splicing content function showall(json, parent) { for (var i in json) { //There are child nodes traversal if (json[i]. > 0) { //Create li var li = $('<li class="layui-nav-item layui-nav-itemed"></li>'); $(li).append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" >'+json[i].dept_name+'</a>'); $(li).append('<ul class="layui-nav-child"></ul>').appendTo(parent); //Select UL Callback showall(json[i].deptChild, $(li).children().eq(1)); } //No children else { $('<li></li>').append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" >'+json[i].dept_name+'</a>').appendTo(parent); } } } });
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links