我是 React 和 Js 的新手,我想了解这行代码(它是 JSX 内部的 Js):<h5 className="recipes__title"> {item.recipe.label < 20 ? `${item.recipe.label}` : `${item.recipe.label.substring(0, 25)}...` }</h5>任何人都知道如何阅读和理解它?
2 回答
TA贡献1906条经验 获得超3个赞
<h5 className="recipes__title"> //An html header
//Containing...
{
item.recipe.label < 20 ? // If the item.recipe.label is less than 20 then...
`${item.recipe.label}` // the label
: `${item.recipe.label.substring(0, 25)} //else the first 25 characters of the label followed by
...` // the string "..."
}
</h5>
您可以在此处找到有关三元运算符(有条件地解析为两个表达式之一的表达式)的信息
您可以在此处找到有关模板文字(可以包含要解析的 javascript 的字符串)的信息
添加回答
举报
0/150
提交
取消
