Dar*_*ong 2 javascript conditional-operator reactjs
如果字符串超过 50 个字符,是否可以使用三元运算符添加 '...'?
我像这样尝试过,但它不起作用。
{post.title.substring(0, 50) + post.title.length > 50
? '...'
: ''}
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
也许你可以这样做:
var shortTitle = post.title.length > 50 ? post.title.substring(0,50) + "..." : post.title;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3228 次 |
| 最近记录: |