react-component / cascader

cascade select in one box

Home Page:https://cascader-react-component.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

querySelect报错

accwill opened this issue · comments

commented

const ele = containerRef.current?.querySelector<HTMLElement>(
`li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes
);

当代码中Selector中存在双引号时,代码将会抛出异常

  • 测试代码: document.querySelector('"asdlfjlksj"')

  • 异常信息如下所示

Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '"asdlfjlksj"' is not a valid selector.
commented
      try {
        ele = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelector("li[data-path-key=\"".concat(cellKeyPath.replace(/\\{0,2}"/g, '\\"'), "\"]"));
      } catch(e) {
      }

我暂时在我的代码中打了个补丁