欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

easyui-combotree指定key和text

程序员文章站 2022-05-18 20:52:22
...

原版easyu没有对combotree组件提供valueField和textField的指定,网上查找资料后得到如下解决方案

$.fn.tree.defaults.loadFilter = function(data, parent) {
	var options = $(this).data().tree.options;
	var idField = options.idField || 'id',
	textField = options.textField || 'text',
	iconField = options.iconField || 'iconCls',
 
	attributes = options.attributes || [];
 
	var transform = function(node) {
		if (!node['id'] && node[idField]) 
			node['id'] = node[idField];
		if (!node['text'] && node[textField]) 
			node['text'] = node[textField];
		if (!node['iconCls'] && node[iconField]) 
			node['iconCls'] = node[iconField];
	
		if (attributes && $.isArray(attributes)) {
			if (!node['attributes']) {
				node['attributes'] = {};
			}
 
			for (var i = 0; i < attributes.length; i++) {
				node['attributes'][attributes[i]] = node[attributes[i]];
			}
		}
 
		if (node['children']) {
			for (var i = 0; i < node['children'].length; i++) {
				transform(node['children'][i]);
			}
		}
	}
 
	for (var i = 0; i < data.length; i++) {
		transform(data[i]);
	}
 
	return data;
}
 
$.fn.combotree.defaults.loadFilter = $.fn.tree.defaults.loadFilter;

 

相关标签: combotree