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;
上一篇: 所有可能幻方解法使用回溯
下一篇: js递归数据处理