ztree版本:v3.5.35
做个树的查询功能,要高亮显示搜索的文字,后台给节点名称加上了html标签,类似如下代码:
nodeName.replace(searchKey, "<span style='color:red;'>" + searchKey + "</span>");
生成树后成了:
通过调试源码,发现在如下代码处做了转义:
- makeDOMNodeIcon: function (html, setting, node) {
- var nameStr = data.nodeName(setting, node), //这里 ↓↓↓
- name = setting.view.nameIsHTML ? nameStr : nameStr.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
- html.push("<span id='", node.tId, consts.id.ICON,
- "' title='' treeNode", consts.id.ICON, " class='", view.makeNodeIcoClass(setting, node),
- "' style='", view.makeNodeIcoStyle(setting, node), "'></span><span id='", node.tId, consts.id.SPAN,
- "' class='", consts.className.NAME,
- "'>", name, "</span>");
- },
去掉后效果:
联系客服