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事件了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM