效果图:

先引用,顺序很重要

<script src="~/Content/bootstrap-table/bootstrap-table.min.js"></script>
<link href="~/Content/bootstrap-table/extensions/tree-table/jquery.treetable.css" rel="stylesheet" />
<script src="~/Content/bootstrap-table/extensions/tree-table/jquery.treetable.js"></script>
<link href="~/Content/bootstrap-table/extensions/tree-table/bootstrap-table-tree-table.css" rel="stylesheet" />
<script src="~/Content/bootstrap-table/extensions/tree-table/bootstrap-table-tree-table.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#dgvInfo").bootstrapTable({
method: "GET",
url: "@Url.Action("TreeJson")",
contentType: "application/x-www-form-urlencoded",
datatype: 'json',
undefinedText: '',
striped: false,//隔行 渐变色
classes: "table table-hover",
clickToSelect: true,
queryParams: function (params) {
return {
menu_Name: $.trim($("#menu_Name").val()),
userName: $.trim($("#userName").val())
}
},
onClickRow: function (row, dom, field) {
$("#dgvInfo").bootstrapTable('uncheckAll');
//$("#dgvInfo").bootstrapTable("checkBy", { field: "gid", values: [dom.data('index')] });
}
}); //表格 - 操作 - 事件
window.actionEvents = {
'click #update-selected': function (e, value, row, index) {
SetChildInsurMsg('修改菜单', row)
},
'click #delete-selected': function (e, value, row, index) {
$.ajax({
url: '@Url.Action("DeleteMeun")',
type: 'post',
dataType: 'json',
data: row,
success: function (data) {
console.log(data.message);
searchData();
},
error: function () {
layer.alert('发生错误', {
skin: 'layui-layer-molv',
closeBtn: 0
});
}
});
}
};
}); function funcNmStyle(value, row, index) {
return { css: { "white-space": "nowrap" } };
} function funcNmFormatter(value, row) {
return ' <i class="' + row.menu_Icon + '">' + value+'</i>';
//<a href="@Url.Action("Update")?FunctionID=' + row.gid + '">' + value + '</a>
} function Operations(value, row, index) {
var str = '<button type="button" id="update-selected" class="btn btn-primary btn-sm"><i class="fa fa-edit"></i>修改</button>&nbsp;&nbsp;<button type="button" id="delete-selected" class="btn btn-danger btn-sm"><i class="fa fa-trash-o"></i>删除</button>';
return str;
} function IsPermissionFormatter(value, row) {
var str = '<input type=checkbox class = "disabled" ' + ((row.menu_IsShow==1) ? 'checked' : '') + ' disabled></input>';
return str;
} function searchData() {
$("#dgvInfo").bootstrapTable('refresh', {
url: '@Url.Action("TreeJson")'
});
} function SetChildInsurMsg(title, rows) {
if (rows == null) {
var selectrow = $("#dgvInfo").bootstrapTable('getSelections')[0];
if (selectrow == null) {
alert("选择父菜单");
return;
}
} layer.open({
type: 2, //因为layer弹出层需要一个页面,所以是iframe弹出层,因此type: 2。
title: title,
shadeClose: true,
shade: 0.4,
area: ['60%', '60%'],
content: '@Url.Action("Info")',
btn: ['确定', '关闭'],
success: function (layero, index) {
if (rows != null) {
var body = layer.getChildFrame('body', index); //巧妙的地方在这里哦,获取layer打开页面的数据
body.contents().find("#gid").val(rows.gid);
body.contents().find("#menu_Num").val(rows.menu_Num);
body.contents().find("#menu_Name").val(rows.menu_Name);
body.contents().find("#menu_Url").val(rows.menu_Url);
body.contents().find("#menu_Icon").val(rows.menu_Icon);
body.contents().find("#menu_Iconi").addClass(rows.menu_Icon);
body.contents().find("#menu_IsShow").val(rows.menu_IsShow);
body.contents().find("#menu_ParentID").val(rows.menu_ParentID);
body.contents().find("#menu_ParentName").val(rows.menu_ParentName);
GetFunction(rows, body);
}
else {
var body = layer.getChildFrame('body', index); //巧妙的地方在这里哦
body.contents().find("#menu_ParentID").val(selectrow.gid);
body.contents().find("#menu_ParentName").val(selectrow.menu_Name);
}
},
yes: function (index) {
var res = window["layui-layer-iframe" + index].callbackdata();
var funs = window["layui-layer-iframe" + index].GetFunctions();
var obj = JSON.parse(res);
var functions = JSON.parse(funs);
if (obj.menu_Name.length > 0) {
if (rows != null) {
updatemenu(obj, functions, index)
} else {
addmenu(obj, functions, index);
}
}
else {
layer.alert('请填写必输项。', {
skin: 'layui-layer-molv',
closeBtn: 0
});
}
},
cancel: function () {
//右上角关闭回调
}
});
} //获取功能
function GetFunction(row, body) {
$.ajax({
url: '@Url.Action("GetMenuFunction")',
type: 'get',
dataType: 'json',
data: {
mid: row.gid
},
success: function (data) {
for (var i = 0; i < data.length; i++) {
body.contents().find("input[value=" + data[i].menuFunction_FunctionID + "]").attr("checked", true)
//.iCheck('check');
}
},
error: function () {
alert("发生错误!");
}
});
}; function addmenu(data, functions, index) {
$.ajax({
url: '@Url.Action("AddMenu")',
type: 'post',
dataType: 'json',
data: {
model: data,
functions: functions
},
success: function (data) {
if (data.type == 1) {
layer.close(index);
searchData();
} else {
alert(data.message);
}
},
error: function () {
alert("发生错误!");
}
});
}; function updatemenu(data, functions, index) {
$.ajax({
url: '@Url.Action("UpdateMenu")',
type: 'post',
dataType: 'json',
data: {
model: data,
functions: functions
},
success: function (data) {
if (data.type == 1) {
layer.close(index);
searchData();
} else {
alert(data.message);
}
},
error: function () {
alert("发生错误!");
}
});
};
</script>

bootstrap的tree使用的更多相关文章

  1. 多层json的构造,取值,还有使用bootstrap的tree view在前端展示的相关问题

    bootstrap-tree view是一款非常好用的插件,它可以添加任意多层节点,效果如下所示: 使用之前需要在HTML页面添加依赖文件: <link href="bootstrap ...

  2. bootstrap的tree控件

    地址:http://runjs.cn/detail/xtte94ls http://runjs.cn/code/xtte94ls

  3. 10+ 最流行的 jQuery Tree 菜单插件

    jstree – jQuery Tree Plugin With HTML & JSON Data jstree is a lightweight and flexible jQuery pl ...

  4. Mega的简单使用

    Table of Contents 1 Mega画树的简单应用 2 fas格式文件的准备 3 用生成的.meg画树 4 生出树的处理 4.1 修改内容,添加标注 4.2 导出 4.3 后面随着学习的进 ...

  5. Flsk-Bootstrap-2

    目录 Flsk-Bootstrap-2 结构 解压Bootstrap 制作基础模板 视图函数 初始文件 启动文件 浏览器 Flsk-Bootstrap-2 参考:Flask 项目中使用 bootstr ...

  6. 【英文文档】 Installing Go from source Go语言官方编译指南 2019.02.27

    Introduction Go is an open source project, distributed under a BSD-style license. This document expl ...

  7. Bootstrap树控件(Tree控件组件)使用经验分享

    前言:很多时候我们在项目中需要用到树,有些树仅仅是展示层级关系,有些树是为了展示和编辑层级关系,还有些树是为了选中项然后其他地方调用选中项.不管怎么样,树控件都是很多项目里面不可或缺的组件之一.今天, ...

  8. 基于bootstrap样式的tree,

    <!doctype html><html lang="zh"><head> <meta charset="UTF-8" ...

  9. BootstrapQ 包Bootstrap tree,dialog等待

    官方网站:http://uikoo9.com/bootstrapQ why 事实上bootstrap已经非常好了,唯一的软肋就是js方面有些薄弱,对照easyui就知道了. 能够非常明显的知道boot ...

随机推荐

  1. Comparison and difference for Default geodatabase,Current workspace,Scratch workspace,Home Folder

    Comparison and difference for Default geodatabase,Current workspace,Scratch workspace,Home Folder 商务 ...

  2. return语句——学习笔记

    return,可以提前结束其所在函数. 函数内不写,会自动加上return. 非引用返回: 引用返回:a=3,b=3 注意事项: 两种修改字符串某一位置值的方式:

  3. supervisord守护进程的使用

    原文链接:http://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyth ...

  4. Mysql的三种数据类型

    Mysql的三种数据类型 1.数值类型 2.日期和时间类型 3.字符串类型 00x1 [数值类型] 00x2 [日期和时间类型] 00x3 [字符串类型]

  5. NodeVisitor

    /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...

  6. 设置pycharm文件默认换行符onfiguring Line Separators

    http://www.jetbrains.com/help/pycharm/2016.2/configuring-line-separators.html PyCharm makes it possi ...

  7. Spring cloud微服务安全实战-3-9API安全机制之审计日志

    首先说一下审计日志的处理.审计日志处理的位置,应该是在认证之后,授权之前.因为只有你在认证之后,你才能知道这个请求到底是谁发出来的,谁在做这个事情.在这个授权之前,这样的话那些被拒绝掉的请求.在响应的 ...

  8. 敏感信息直接在 nginx 通过环境变量设置

    通常我们在维护PHP线上项目的时候,为了隔离配置和代码,会使用fastcgi_param的形式将环境变量定义在Nginx的配置文件中(Apache可以使用SetEnv指令).这样在PHP-FPM运行过 ...

  9. Mac或者linux系统自动加载python tab补全功能

    因为mac OS属于类unix系统,所以基本和linux系统使用相差不大,只是用户登陆时自动执行环境变量文件的区别 mac系统: ShanedeMBP:login_api shane$ vi ~/.b ...

  10. 比较两个数组的键名,并返回交集:array_intersect_key

    $a1=array("a"=>"red","b"=>"green","c"=>&q ...