easy-ui 中的事件触发 (tree)

easy-ui可以为插件添加事件,但没有触发事件的处理(可能是未找到),所以有时候,我们需要通过程序去触发某个插件指定的事件时,就一筹莫展了

以Tree插件为例 ,添加了onClick事件

jQuery("#tree_syscode_" + item.ValueCode).tree({
					method : 'get',
					url : String
							.format(
									"/tools/ajax.aspx?ac=GetSystemCodeTree&type={0}&r={1}",
									item.ValueCode, Math.random()),
					lines : true,
					onClick : function(node) {...}
});

  

可能我们需要在数据加载完成后,自动加载第一个树形节点关联的数据

jQuery("#tree_syscode_" + item.ValueCode).tree({
					method : 'get',
					url : String
							.format(
									"/tools/ajax.aspx?ac=GetSystemCodeTree&type={0}&r={1}",
									item.ValueCode, Math.random()),
					lines : true,
					onClick : function(node) {
						...
					},
					onLoadSuccess : function(node, data) {
						if (data.length == 0) {
							return;
						}

						// 首次加载时,node为null
						if (node == null) {
							...
							// 这儿是初始化Tree的的处理,需要触发Tree.onClick
						}
					}
				});

 此时就需要触发Tree的onClick事件了,但easyui没有添加事件直接调用的方法,那么我们变通一下,通过options方法得到Tree绑定的事件

 

jQuery("#tree_syscode_" + item.ValueCode).tree({
					method : 'get',
					url : String
							.format(
									"/tools/ajax.aspx?ac=GetSystemCodeTree&type={0}&r={1}",
									item.ValueCode, Math.random()),
					lines : true,
					onClick : function(node) {
						...
					},
					onLoadSuccess : function(node, data) {
						if (data.length == 0) {
							return;
						}

						// 首次加载时,node为null
						if (node == null) {
							var s_node = $(this).tree('find', data[0].id);
							var func = $(this).tree('options').onClick;

							if (func != null) {
								func.call(this, s_node);
							}
						}
					}
				});

  这样就可以触发Click事件了

原文地址:https://www.cnblogs.com/dreamcat/p/7372985.html