html 布局中的错误 '","' 预期.ts(1005)



这是我第一次尝试为我的ReactJS项目构建真正的布局,但我遇到了这个错误(错误','应为.ts(1005((,无法完成。这是我打算构建的布局的html:

<div>
{selectedInput === null ? (
<div>
<div>
some html
</div>
<div>
{
array.slice(3, 100).map((doc, index) =>
<div>
some html
</div>
} <== here the error
</div>
</div>
) : (
<div>
some html
</div>
)
}
</div>

我在最后一个括号中遇到错误

编辑:我向回复的人道歉,但我想合成代码,我做得很糟糕。现在我已经把正确的版本。

您错过了map的右括号)

尝试添加括号。

更新代码:

<div>
{selectedInput === null ? (
<div>
<div>some html</div>
<div>
{array.slice(3, 100).map((doc, index) => (
<div>some html</div>
))}
</div>
</div>
) : (
<div>some html</div>
)}
</div>

您忘记添加大括号"}"。

这应该工作

<div>
{selectedInput === null ? (
<div>
<div>
some html
</div>
<div>
{
getOrder.slice(3, 100).map((doc, index) =>
<div>
some html
</div>
}  <== here the error
</div>
</div>
}
</div>

错误太多。

感觉自己不明白它是如何运作的。

这段代码应该可以工作,但您需要彻底理解它。

<div>
{selectedInput === null ? (
<div>
<div>some html</div>
<div>
{getOrder.slice(3, 100).map((item, i) => {
return <div key={i}>some html</div>;
})}
</div>
</div>
) : (
<div>Another content</div>
)}
</div>;

最新更新