目标:让浏览器在任务描述超过两行时响应式地呈现溢出文本省略号,而不是在没有时。
下面是我的 React 组件,clamp
我们正在导入的是https://github.com/josephschmitt/Clamp.js的本地副本
import React from 'react'
import clamp from 'client/util/clamp'
import { findDOMNode } from 'react-dom'
const TextDescription = ({ name, description, dueDate }) => {
return (
<div>
<div className='desc-text' ref={(clampee) => {clampee && clamp(findDOMNode(clampee), { clamp: 2 })}}>
<strong>{name} Task: </strong> {description}.
</div>
<div>
Due: {dueDate}
</div>
</div>
)
}
这完全可以在 Chrome 中运行(请参见上面的屏幕截图),因为它是 webkit 浏览器,甚至没有在getLastChild
函数中输入这个有问题的代码区域clamp.js
from .js 上面链接。
错误:
[object Error] {description: "Unable to get property 'children' of undefined or null reference", name: "TypeError", number: "-2146823281"}
我已经看过这个线程https://github.com/josephschmitt/Clamp.js/issues/24
并尝试了他们的建议,明确指定了clamp参数并将CSS设置为:
.desc-text
display: block;
line-height: 18px;
margin-top: -20px;
我们还尝试修改clamp.js(上面链接)中的第117行以包括elem.lastChild
现在:
if (elem.lastChild && elem.lastChild.children && elem.lastChild.children.length > 0) { ...
结果在进入下一个 if 时会出现稍微不同的错误:
[object Error] {description: "Unable to get property 'parentNode' of undefined or null reference", name: "TypeError", number: "-2146823281"}
有人知道如何让线夹在 IE 中工作吗?