我目前正在尝试使 HTML 表在 React 中工作,但有些事情并没有按照应有的方式进行。我确实得到了渲染输出,但出现错误:<tr> cannot appear as a child of <div>。
我试图在网上找到它,但我使用的技术似乎并不经常使用,所以如果我做错了,请赐教。
先感谢您!
getTableContent = (arr) => {
let result = [];
arr.forEach(function (item, i) {
result.push(
<table key={item.productType}>
<thead>{item.productType}</thead>
<tbody>
{item.contents.forEach(function (nextItem, j) {
result.push(
<tr key={nextItem.type}>
<td>{nextItem.type}</td>
<td>{nextItem.count}</td>
</tr>
)
})}
</tbody>
</table>
);
});
return result;
};
render() {
return (
<div>{this.getTableContent(productSpecification)}</div>
);
}
Run Code Online (Sandbox Code Playgroud)
数据如下:
const productSpecification = [
{
productType: "abc", contents: [
{type: "abc", count: 231},
{type: "abc", count: 56},
{type: "abc", …Run Code Online (Sandbox Code Playgroud) 我想弄清楚如何根据作者(参考)检索特定文章,我当前的功能检索所有文章,但我只想要作者特定的文章
const resp = yield client.getEntries({
'fields.insightsArticle': true,
'fields.excludeCountries[nin]': country,
'fields.publicationDate[lte]': moment(new Date()).toISOString(),
'fields.author.fields.firstname': author.firstName,
'fields.author.fields.lastname': author.lastName,
content_type: 'insight',
include: 2,
order: '-fields.publicationDate',
limit,
locale,
});
Run Code Online (Sandbox Code Playgroud)
我从 contentful 获得的当前日志是:“搜索参考文献时,您必须指定参考文献的内容类型。请发送内容类型 ID 作为查询参数”
我明白了,因为我将内容类型定义为洞察力。
欢迎任何建议!