reactjs - 反应解析失败,意外的令牌
问题描述
我正在尝试创建一个基于后端生成新行的 Dynamic Material UI Flex 框。我的想法是关闭当前的外框并根据标志创建一个新的
所以我写了下面的代码
<Box p="1em">
<Box display="flex">
{tabs.map((t, index) => {
return (
<>
<Box flex={resourcesTabs[index][0] == null ? 1 : resourcesTabs[index][0]['width_class']} ml="1em">
<Typography variant="h6" gutterBottom>{t}</Typography>
{resourcesFields[index] && resourcesFields[index].map((f, index) =>
generateInputField(f, index)
)}
</Box>
{resourcesTabs[index][0]['new_line_after'] && </Box><Box display="flex">}
</>
);
})}
</Box>
</Box>
但我收到以下错误
Parsing error: Unexpected token
因为它抱怨关闭此行的打开标签动态
{resourcesTabs[index][0]['new_line_after'] && (</Box><Box display="flex">}
知道如何解决这个问题吗?
解决方案
我通过用网格替换框来修复它,如下代码
<div style={{ padding: 10 }}>
<Grid container spacing={3}>
{tabs.map((t, index) => {
return (
<>
<Grid item xs={resourcesTabs[index][0] == null ? 6 : resourcesTabs[index][0]['width_class']} >
<Typography variant="h6" gutterBottom>{t}</Typography>
{resourcesFields[index] && resourcesFields[index].map((f, index) =>
generateInputField(f, index)
)}
</Grid>
</>
);
}
)}
</Grid>
</div>
推荐阅读
- c++ - 使用 boost-spirit 将字符串解析为 QStrings 的结构
- java - 如何舍入 Spark sql 中的值
- android - 添加/删除项目时,是否可以为回收站视图的受限高度变化设置动画?
- html - 仅使用 CSS 滚动消息
- ios - Xcode缺少y位置的约束警告,但已设置
- bash - 当我尝试在 shell 脚本中执行没有先前值的代码时,什么代码函数将有助于请求输入
- typescript - 除了函数 isType() 之外,如何从 saga 动作中获取有效负载?
- ionic4 - 如何覆盖 .inner-scroll 类背景颜色?
- angular - ionic 4 - ionic cordova build android --prod 不会将 angular environment.prod 复制到环境
- excel - excel VBA查找不适用于特定值