首页 > 解决方案 > 如何从 quill delta 对象制作描述文本

问题描述

我目前正在制作一个有博客的网站(我正在使用 quill 更准确地react-quilljs),我现在想在博客卡中添加简短描述

const jsonText = JSON.parse(article.body);

  let text = jsonText.ops[0].insert;

这是我从 delta 对象获得的示例数据

ops:[
   insert:"text ...."
 ]

样本数据输出

我希望有可能进行例如不删减单词并显示少于 50 个单词的描述。如果它可以只呈现没有任何标题属性的文本单词。是否有任何选择来实现它,或者我必须保留我现在使用的东西。

标签: javascriptreactjsquillreact-quill

解决方案


你可以试试 text-overflow text-overflow我加了一个例子。

div.b {
  white-space: nowrap; 
  width: 250px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid #000000;
}
<div class="b">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release</div>


推荐阅读