TreeNode

  • 在v3 升级到 v4版本的情况下, 原本的 loop 写法被提示报错, children of Tree is depreacated Please use treeData instead

相关问题可参考

  1. import React, { useRef, useEffect } from '@alipay/bigfish/react';
  2. const EllipsisTip = ({text}: { text: string }) => {
  3. const divRef = useRef<HTMLDivElement | null>(null);
  4. useEffect(() => {
  5. if (divRef.current) {
  6. const parent = divRef.current.parentElement;
  7. const childs = Array.from(parent?.children ?? []);
  8. const total = childs.reduce((prev, next) => prev + Number(next?.getBoundingClientRect?.()?.width),0);
  9. const texts = divRef.current.innerText;
  10. const diff = total - divRef.current?.getBoundingClientRect?.().width;
  11. /** 每个字符平均宽度 */
  12. const textWidth = diff / texts.length;
  13. const parentWidht = Number(parent?.getBoundingClientRect?.()?.width);
  14. const width = parentWidht - diff;
  15. const sliceNum = Math.floor(width / textWidth) - 3;
  16. divRef.current.style = 'overflow: hidden; white-space: nowrap;'
  17. divRef.current.innerText = texts.slice(0, sliceNum) + '...';
  18. }
  19. }, [divRef])
  20. return (
  21. <div ref={divRef}>{text}</div>
  22. )
  23. }
  24. export default EllipsisTip;