easyui Combotree 怎么加载数据 支持多选

1、开发环境vs2012 mvc4  c#

2、HTML前端代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataGridTest.aspx.cs" Inherits="MvcAppTest.DataGridTest" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title><link href="Easyui/themes/default/easyui.css" rel="stylesheet" /><script src="Easyui/jquery-1.7.2.min.js"></script><script src="Easyui/jquery.easyui.min.js"></script><script src="Easyui/locale/easyui-lang-zh_CN.js"></script><script src="IndusJS/kzEasyuiCombotree.js"></script><style type="text/css">/*.datagrid-btable .datagrid-cell{overflow: hidden;text-overflow:ellipsis;white-space: nowrap;} .datagrid-header {position: absolute; visibility: hidden;}*/</style><script type="text/javascript">var $winPro;$(function () {       showProTree();$winPro = $('#test-windowPro').window({title: '企业存在困难',width: 400,height: 300,shadow: true,modal: true,iconCls: 'icon-add',closed: true,minimizable: false,maximizable: false,collapsible: false,buttons: [{text: '添加',handler: function () {}}]});});function showProTree() {    $("#IDPro").combotree({url: 'Home/HandlerProblemFromFile',valueField: 'id',textField: 'text',width: 250,multiple: true, //这个选项设置多选功能
                onClick: function (node) {},panelHeight: 300,editable: true,onLoadSuccess: function (node, data) {$(this).tree('collapseAll');   //关闭树节点var root = $(this).tree("getRoot");      //展开根节点if (root != null) {$(this).tree("expand", root.target);var childrens = $(this).tree("getChildren", root.target);for (var i = 0; i < childrens.length; i++) {if (childrens[i].id == '0') {$(this).tree("expand", childrens[i].target);}}}}});$(".combo-text").bind("input propertychange", function () {$('#IDPro').combotree('tree').tree("search", $(this).val());if ($(this).val() == "" || null == $(this).val()) {$('#IDPro').combotree('tree').tree("expandAll");}});}function testPro() {var tree = $('#IDPro').combotree('tree');//获取当前选中的节点var data = tree.tree('getChecked');if (data) {if (data.length > 0) {var str = new Array();for (var i = 0; i < data.length; i++) {str.push(data[i].text);}var myStr = str.join(',');$('#PROBLEMITEM').val(myStr);$winPro.window('close');}}}function testPro01(){ $winPro.window('close'); }function SelectPro() {$winPro.window('open');}</script>
</head>
<body><div><table id="wg"></table></div><br /><input type="text" id="PROBLEMITEM" value="" /> &nbsp;&nbsp; <input style="width:100px;height:31px;" type="button" value="选择" onclick="SelectPro()" /><div id="test-windowPro" class="easyui-window"  title="Login" style="width: 600px; height: 450px;"><div style="padding:10px 0px 0px 20px;"> <input  id="IDPro" value="" /></div><div style="margin-top:15px;text-align:center;"><input type="button" style="width:100px;" onclick="testPro()" value="选择" />&nbsp;&nbsp;&nbsp;<input type="button" style="width:100px;" onclick="testPro01()" value="取消" /></div>
</div>
</body>
</html>

3、后台代码

   public ActionResult HandlerProblemFromFile(){string path = Server.MapPath("~/loaclData/tree_data4.json"); return File(path, "application/json");}

4、项目结构

5、tree_data4.json

[
{
"id":1,
"text":"土地"
},
{
"id":2,
"text":"资金"
},
{
"id":3,
"text":"水电"
},
{
"id":4,
"text":"基础设施"
},
{
"id":5,
"text":"手续审批"
},
{
"id":6,
"text":"市场"
},
{
"id":7,
"text":"招工"
}

]

6、kzEasyuiCombotree.js

(function ($) {//扩展combotree搜索功能
    $.extend($.fn.tree.methods, {search: function (jqTree, searchText) {// easyui tree的tree对象。可以通过tree.methodName(jqTree)方式调用easyui tree的方法var tree = this;// 获取所有的树节点var nodeList = getAllNodes(jqTree, tree);// 如果没有搜索条件,则展示所有树节点searchText = $.trim(searchText);console.log(searchText);if (searchText == "") {console.log('控制');for (var i = 0; i < nodeList.length; i++) {$(".tree-node-targeted", nodeList[i].target).removeClass("tree-node-targeted");$(nodeList[i].target).show();}// 展开已选择的节点(如果之前选择了)var selectedNode = tree.getSelected(jqTree);if (selectedNode) {tree.expandTo(jqTree, selectedNode.target);}return;}// 搜索匹配的节点并高亮显示var matchedNodeList = [];if (nodeList && nodeList.length > 0) {var node = null;for (var i = 0; i < nodeList.length; i++) {node = nodeList[i];if (isMatch(searchText, node.text)) {matchedNodeList.push(node);}}// 隐藏所有节点for (var i = 0; i < nodeList.length; i++) {$(".tree-node-targeted", nodeList[i].target).removeClass("tree-node-targeted");$(nodeList[i].target).hide();}// 折叠所有节点
                tree.collapseAll(jqTree);// 展示所有匹配的节点以及父节点for (var i = 0; i < matchedNodeList.length; i++) {showMatchedNode(jqTree, tree, matchedNodeList[i]);}}},showChildren: function (jqTree, node) {// easyui tree的tree对象。可以通过tree.methodName(jqTree)方式调用easyui tree的方法var tree = this;// 展示子节点if (!tree.isLeaf(jqTree, node.target)) {var children = tree.getChildren(jqTree, node.target);if (children && children.length > 0) {for (var i = 0; i < nodeList.length; i++) {if ($(children[i].target).is(":hidden")) {$(children[i].target).show();}}}}},scrollTo: function (jqTree, param) {// easyui tree的tree对象。可以通过tree.methodName(jqTree)方式调用easyui tree的方法var tree = this;// 如果node为空,则获取当前选中的nodevar targetNode = param && param.targetNode ? param.targetNode : tree.getSelected(jqTree);if (targetNode != null) {// 判断节点是否在可视区域var root = tree.getRoot(jqTree);var $targetNode = $(targetNode.target);var container = param && param.treeContainer ? param.treeContainer : jqTree.parent();var containerH = container.height();var nodeOffsetHeight = $targetNode.offset().top - container.offset().top;if (nodeOffsetHeight > (containerH - 30)) {var scrollHeight = container.scrollTop() + nodeOffsetHeight - containerH + 30;container.scrollTop(scrollHeight);}}}});function showMatchedNode(jqTree, tree, node) {// 展示所有父节点
        $(node.target).show();$(".tree-title", node.target).addClass("tree-node-targeted");var pNode = node;while ((pNode = tree.getParent(jqTree, pNode.target))) {$(pNode.target).show();}// 展开到该节点
        tree.expandTo(jqTree, node.target);// 如果是非叶子节点,需折叠该节点的所有子节点if (!tree.isLeaf(jqTree, node.target)) {tree.collapse(jqTree, node.target);}}function isMatch(searchText, targetText) {return $.trim(targetText) != "" && targetText.indexOf(searchText) != -1;}function getAllNodes(jqTree, tree) {var allNodeList = jqTree.data("allNodeList");if (!allNodeList) {var roots = tree.getRoots(jqTree);allNodeList = getChildNodeList(jqTree, tree, roots);jqTree.data("allNodeList", allNodeList);}return allNodeList;}function getChildNodeList(jqTree, tree, nodes) {var childNodeList = [];if (nodes && nodes.length > 0) {var node = null;for (var i = 0; i < nodes.length; i++) {node = nodes[i];childNodeList.push(node);if (!tree.isLeaf(jqTree, node.target)) {var children = tree.getChildren(jqTree, node.target);childNodeList = childNodeList.concat(getChildNodeList(jqTree, tree, children));}}}return childNodeList;}
})(jQuery);

7、easyUI引用文件

链接:https://pan.baidu.com/s/1KxL2QeVEbEVHU9UxV6LBWw
提取码:cwbd

转载于:https://www.cnblogs.com/net064/p/10265371.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/412428.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[vue] 在vue事件中传入$event,使用e.target和e.currentTarget有什么区别?

[vue] 在vue事件中传入$event&#xff0c;使用e.target和e.currentTarget有什么区别&#xff1f; event.currentTarget指向事件所绑定的元素&#xff0c;而event.target始终指向事件发生时的元素。个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&am…

idea 错误: 找不到或无法加载主类(汇总贴)

大家好&#xff0c;我是烤鸭&#xff1a; 现在是采坑实录。 idea 错误: 找不到或无法加载主类 xxx.xxx.xxxxx JDK环境&#xff0c;maven项目还是ee还是web项目&#xff0c;是否都正常。 如果是用idea打开的话,在源码目录上点击右键,然后找到Mark directory as->source ro…

C语言——生命游戏(初始

#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> #include<time.h>#define High 25 #define Width 50 //游戏画面的尺寸int cells[High][Width]; //所有位置细胞生为1&#xff0c;死亡为0void gotoxy(…

[vue] 在.vue文件中style是必须的吗?那script是必须的吗?为什么?

[vue] 在.vue文件中style是必须的吗&#xff1f;那script是必须的吗&#xff1f;为什么&#xff1f; style 不是必须的&#xff0c;script 是必须的&#xff0c;而且必须要写上个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定…

爬虫,关于 video 标签 src 带有blob:http的 一些想法

大家好&#xff0c;我是烤鸭&#xff1a; 之前玩爬虫的时候&#xff0c;看到过video标签中src属性引入的blob:http:xxxx&#xff0c;当时没找到解决思路&#xff0c;今天又遇到类似问题&#xff0c;就试着找了一下。 这是有人问过 https://vimeo.com/ 这个网站的视频怎么下载。…

4Python切片功能剖析

引用文章&#xff1a;https://mp.weixin.qq.com/s/NZ371nKs_WXdYPCPiryocw 切片基础法则&#xff1a; &#xff08;1&#xff09;公式[i : n : m]&#xff0c;i为起始位置索引(当i为首位0可省略)&#xff0c;in为结束位置索引(当n为长度len(li)可省略)&#xff0c;m为步长&…

[vue] vue怎么实现强制刷新组件?

[vue] vue怎么实现强制刷新组件&#xff1f; 强制重新渲染this.$forceUpdate()强制重新刷新某组件//模版上绑定key <SomeComponent :key"theKey"/> //选项里绑定data data(){return{theKey:0} } //刷新key达到刷新组件的目的 theKey;个人简介 我是歌谣&#x…

Success Rate CodeForces - 807C (数学+二分)

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational …

[vue] 实际工作中,你总结的vue最佳实践有哪些?

[vue] 实际工作中&#xff0c;你总结的vue最佳实践有哪些&#xff1f; .babelrc 是目前 babel-polyfill 的最佳实践 { "presets": [ [ "babel/preset-env", { "corejs": "3", "modules": false, "useBuiltIns": …

Epson打印机连接wifi

环境 Epson L3153 打印机联通无线光猫 背景 最近家里的联通宽带不太稳定&#xff0c;经常断网。今天打了联通客服电话&#xff0c;师傅上门来&#xff0c;说可能是光猫用的时间太长了&#xff0c;换了一个新的联通光猫&#xff0c;问题解决。 wifi的名称是 CU_Y3ft 和 CU_Y3…

[vue] vue给组件绑定自定义事件无效怎么解决?

[vue] vue给组件绑定自定义事件无效怎么解决&#xff1f; 两种方式 1、组件外部加修饰符.navtive 2、组件内部声明$emit(自定义事件)个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一…

ES6笔记 -- 变量/语句声明

关于变量声明 let的作用是声明一个作用域为某个代码块({})的变量(称为块级作用域)let不允许变量提升(注: 变量的使用在声明之前)块级作用域里的let命令之前的区域称之为暂时性死区, 这意味着死区内即使是typeof操作也会出错let不允许在相同的作用域内重复声明同一个变量, 值得一…

[vue] vue的属性名称与method的方法名称一样时会发生什么问题?

[vue] vue的属性名称与method的方法名称一样时会发生什么问题&#xff1f; 键名优先级&#xff1a;props > data > methods个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起…

括号序列

题目描述 一个由小括号组成的字符串可以被称为一个括号序列。但一个括号序列可能并不满足括号匹配的要求。因此&#xff0c;我们可以进一步将满足括号匹配的括号序列成为“标准的括号序列。例如字符串")((())"是一个括号序列但不是标准的括号序列&#xff0c;而字符串…

[vue] vue变量名如果以_、$开头的属性会发生什么问题?怎么访问到它们的值?

[vue] vue变量名如果以_、$开头的属性会发生什么问题&#xff1f;怎么访问到它们的值&#xff1f; 报错 变量未定义 以 _ 或 $ 开头的属性 不会 被 Vue 实例代理&#xff0c;因为它们可能和 Vue 内置的属性、API 方法冲突。 你可以使用例如 $data.xxx或者_data.xxx 的方式访问…

[vue] vue使用v-for遍历对象时,是按什么顺序遍历的?如何保证顺序?

[vue] vue使用v-for遍历对象时&#xff0c;是按什么顺序遍历的&#xff1f;如何保证顺序&#xff1f; image 1、会先判断是否有iterator接口&#xff0c;如果有循环执行next()方法 2、没有iterator的情况下&#xff0c;会调用Object.keys()方法&#xff0c;在不同浏览器中&…

[vue] vue如果想扩展某个现有的组件时,怎么做呢?

[vue] vue如果想扩展某个现有的组件时&#xff0c;怎么做呢&#xff1f; 不对原组件进行更改的&#xff1a;使用Vue.extend直接扩展使用Vue.mixin全局混入HOC封装个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大…

typescript在ES3(IE7)环境下使用async、await

因为公司产品需要搞个Web App&#xff0c;但是又需要兼容IE7&#xff0c;这时候整个应用会非常复杂&#xff0c;尤其是在处理异步的时候&#xff0c;在我的选择中有两个方案 callback方案async/await经过衡量以后&#xff0c;决定使用async/await方案 配置typescript环境 $ mkd…

与歌谣通关前端面试题【CSS篇汇总目录】

我是歌谣 放弃很容易 但坚持一定很酷 欢迎 关注公众号小歌谣一起讨论前后端知识 CSS汇总 【CSS】 [css] 圣杯布局和双飞翼布局的理解和区别&#xff0c;并用代码实现 [css] CSS3有哪些新增的特性&#xff1f; [css] 在页面上隐藏元素的方法有哪些&#xff1f; [css] CSS选…

【LeetCode】按 tag 分类索引 (900题以下)

链表&#xff1a;https://www.cnblogs.com/zhangwanying/p/9797184.html &#xff08;共34题&#xff09; 数组&#xff1a;https://www.cnblogs.com/zhangwanying/p/9610923.html &#xff08;共139题&#xff09; 树&#xff1a;https://www.cnblogs.com/zhangwanying/p/67…