javascript - 省略字符串前后的文本 [React Native]

标签 javascript reactjs react-native

正如标题所提到的,我正在尝试找到一种省略字符串数组的方法。我首先考虑使用 ellipsizeMode 属性中的 tailhead 属性,但它说我一次只能使用一个。知道怎么做吗?

最佳答案

如果您知道字符数限制

render(){
const maxLimit=38 //for example
const myText=arrayString.join(" ");

return(
    <Text>
          {myText.length > maxLimit
            ? '...' +
              myText.substring(
                myText.length / 2 - maxLimit / 2,
                myText.length / 2 + maxLimit / 2,
              ) + '...'
            : myText}
     </Text>
);
}

关于javascript - 省略字符串前后的文本 [React Native],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59164488/

相关文章:

javascript - 如何在对 td 元素执行 onclick 时显示/隐藏 div

css - 哪些 CSS 框架与 React 完美配合?

javascript - 在页面加载时在 Chrome 中调试 ReactJs - 使用控制台时,这个和其他所有内容都是未定义的

javascript - ReactJS - 如何设置登录模式?

React-Native Realm 通过主键获取

javascript - 从 1970 年之前的日期数组中获取最高日期

Javascript 没有将代码放在 ID div 中

javascript - 方法发布不适用于 Axios 和 React JS

javascript - 在 ios safari 和 chrome 中使用客户端 javascript 设置安全 cookie

reactjs - AsyncStorage 不存储数据,随后不检索数据