Commit 276d0a3f by 前端

修复bug

1 parent 4ba63d13
...@@ -1445,23 +1445,72 @@ ...@@ -1445,23 +1445,72 @@
} }
} }
function bindEvent() { // function bindEvent() {
$('#brand').on( // $('#brand').on(
'input', // 'input',
helper.debounce(function () { // helper.debounce(function () {
var txt = $(this).val() // var txt = $(this).val()
if (!txt) { // if (!txt) {
treeObj.showNodes(all_nodes) // treeObj.showNodes(all_nodes)
} else { // } else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt) // var nodesList = treeObj.getNodesByParamFuzzy('label', txt)
show_nodes = helper.findShowNode(nodesList, all_nodes) // show_nodes = helper.findShowNode(nodesList, all_nodes)
treeObj.hideNodes(all_nodes) // treeObj.hideNodes(all_nodes)
treeObj.showNodes(show_nodes) // treeObj.showNodes(show_nodes)
} // }
}, 500) // }, 500)
) // )
} // }
function bindEvent() {
$('#brand').on(
'input',
helper.debounce(function () {
var txt = $(this).val();
if (!txt) {
treeObj.showNodes(all_nodes);
} else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt);
var showNodes = [];
nodesList.forEach(function(node) {
showNodes.push(node); // 把当前匹配的节点加入显示列表
// 如果匹配的节点有父节点,也将其父节点加入显示列表
var parentNode = node.getParentNode();
if (parentNode && showNodes.indexOf(parentNode) === -1) {
showNodes.push(parentNode);
}
// 如果匹配的是一级菜单节点,同时把它的所有子节点加入显示列表
if (!parentNode && node.children) {
showNodes = showNodes.concat(node.children);
}
});
// 去除重复节点
showNodes = uniqueNodes(showNodes);
// 先隐藏所有节点,再显示匹配的节点及其相关的父或子节点
treeObj.hideNodes(all_nodes);
treeObj.showNodes(showNodes);
}
}, 500)
);
}
// unique 方法用于确保没有重复的节点
function uniqueNodes(nodes) {
var uniqueNodes = [];
var uniqueKeys = {};
nodes.forEach(function(node) {
if (!uniqueKeys[node.tId]) {
uniqueKeys[node.tId] = true;
uniqueNodes.push(node);
}
});
return uniqueNodes;
};
function setCheckbox(checkedStr, attr) { function setCheckbox(checkedStr, attr) {
if (!checkedStr || !checkedStr.length) { if (!checkedStr || !checkedStr.length) {
return false return false
......
...@@ -1444,22 +1444,71 @@ ...@@ -1444,22 +1444,71 @@
} }
} }
function bindEvent() { // function bindEvent() {
$('#brand').on( // $('#brand').on(
'input', // 'input',
helper.debounce(function () { // helper.debounce(function () {
var txt = $(this).val() // var txt = $(this).val()
if (!txt) { // if (!txt) {
treeObj.showNodes(all_nodes) // treeObj.showNodes(all_nodes)
} else { // } else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt) // var nodesList = treeObj.getNodesByParamFuzzy('label', txt)
show_nodes = helper.findShowNode(nodesList, all_nodes) // show_nodes = helper.findShowNode(nodesList, all_nodes)
treeObj.hideNodes(all_nodes) // treeObj.hideNodes(all_nodes)
treeObj.showNodes(show_nodes) // treeObj.showNodes(show_nodes)
} // }
}, 500) // }, 500)
) // )
} // }
function bindEvent() {
$('#brand').on(
'input',
helper.debounce(function () {
var txt = $(this).val();
if (!txt) {
treeObj.showNodes(all_nodes);
} else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt);
var showNodes = [];
nodesList.forEach(function(node) {
showNodes.push(node); // 把当前匹配的节点加入显示列表
// 如果匹配的节点有父节点,也将其父节点加入显示列表
var parentNode = node.getParentNode();
if (parentNode && showNodes.indexOf(parentNode) === -1) {
showNodes.push(parentNode);
}
// 如果匹配的是一级菜单节点,同时把它的所有子节点加入显示列表
if (!parentNode && node.children) {
showNodes = showNodes.concat(node.children);
}
});
// 去除重复节点
showNodes = uniqueNodes(showNodes);
// 先隐藏所有节点,再显示匹配的节点及其相关的父或子节点
treeObj.hideNodes(all_nodes);
treeObj.showNodes(showNodes);
}
}, 500)
);
}
// unique 方法用于确保没有重复的节点
function uniqueNodes(nodes) {
var uniqueNodes = [];
var uniqueKeys = {};
nodes.forEach(function(node) {
if (!uniqueKeys[node.tId]) {
uniqueKeys[node.tId] = true;
uniqueNodes.push(node);
}
});
return uniqueNodes;
};
function setCheckbox(checkedStr, attr) { function setCheckbox(checkedStr, attr) {
if (!checkedStr || !checkedStr.length) { if (!checkedStr || !checkedStr.length) {
......
...@@ -1426,90 +1426,73 @@ ...@@ -1426,90 +1426,73 @@
} }
} }
function bindEvent() { // function bindEvent() {
$('#brand').on( // $('#brand').on(
'input', // 'input',
helper.debounce(function () { // helper.debounce(function () {
var txt = $(this).val() // var txt = $(this).val()
if (!txt) { // if (!txt) {
treeObj.showNodes(all_nodes) // treeObj.showNodes(all_nodes)
} else { // } else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt) // var nodesList = treeObj.getNodesByParamFuzzy('label', txt)
show_nodes = helper.findShowNode(nodesList, all_nodes) // show_nodes = helper.findShowNode(nodesList, all_nodes)
console.log(show_nodes) // console.log(show_nodes)
treeObj.hideNodes(all_nodes) // treeObj.hideNodes(all_nodes)
treeObj.showNodes(show_nodes) // treeObj.showNodes(show_nodes)
} // }
}, 500) // }, 500)
) // )
} // }
// function bindEvent() {
// $('#brand').on(
// 'input',
// helper.debounce(function () {
// var txt = $(this).val();
// if (!txt) {
// treeObj.showNodes(all_nodes);
// } else {
// var nodesList = treeObj.getNodesByParamFuzzy('label', txt);
// var showNodes = [];
// nodesList.forEach(function(node) {
// showNodes.push(node); // 把当前匹配的节点加入显示列表
// // 如果匹配的节点有父节点,也将其父节点加入显示列表
// var parentNode = node.getParentNode();
// if (parentNode && showNodes.indexOf(parentNode) === -1) {
// showNodes.push(parentNode);
// }
// // 如果匹配的是一级菜单节点,同时把它的所有子节点加入显示列表
// if (!parentNode && node.children) {
// showNodes = showNodes.concat(node.children);
// }
// });
// // 去除重复节点
// showNodes = uniqueNodes(showNodes);
// // 先隐藏所有节点,再显示匹配的节点及其相关的父或子节点
// treeObj.hideNodes(all_nodes);
// treeObj.showNodes(showNodes);
// }
// }, 500)
// );
// }
// unique 方法用于确保没有重复的节点
// function uniqueNodes(nodes) {
// var uniqueNodes = [];
// var uniqueKeys = {};
// nodes.forEach(function(node) {
// if (!uniqueKeys[node.tId]) {
// uniqueKeys[node.tId] = true;
// uniqueNodes.push(node);
// }
// });
// return uniqueNodes; function bindEvent() {
// }; $('#brand').on(
'input',
helper.debounce(function () {
// helper.unique 方法需要确保节点不重复 var txt = $(this).val();
// helper.unique = function(nodes) { if (!txt) {
// var uniqueNodes = []; treeObj.showNodes(all_nodes);
// var uniqueKeys = {}; } else {
var nodesList = treeObj.getNodesByParamFuzzy('label', txt);
var showNodes = [];
nodesList.forEach(function(node) {
showNodes.push(node); // 把当前匹配的节点加入显示列表
// 如果匹配的节点有父节点,也将其父节点加入显示列表
var parentNode = node.getParentNode();
if (parentNode && showNodes.indexOf(parentNode) === -1) {
showNodes.push(parentNode);
}
// 如果匹配的是一级菜单节点,同时把它的所有子节点加入显示列表
if (!parentNode && node.children) {
showNodes = showNodes.concat(node.children);
}
});
// nodes.forEach(function(node) { // 去除重复节点
// if (!uniqueKeys[node.tId]) { showNodes = uniqueNodes(showNodes);
// uniqueKeys[node.tId] = true;
// uniqueNodes.push(node);
// }
// });
// return uniqueNodes; // 先隐藏所有节点,再显示匹配的节点及其相关的父或子节点
// }; treeObj.hideNodes(all_nodes);
treeObj.showNodes(showNodes);
}
}, 500)
);
}
// unique 方法用于确保没有重复的节点
function uniqueNodes(nodes) {
var uniqueNodes = [];
var uniqueKeys = {};
nodes.forEach(function(node) {
if (!uniqueKeys[node.tId]) {
uniqueKeys[node.tId] = true;
uniqueNodes.push(node);
}
});
return uniqueNodes;
};
function setCheckbox(checkedStr, attr) { function setCheckbox(checkedStr, attr) {
if (!checkedStr || !checkedStr.length) { if (!checkedStr || !checkedStr.length) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!