reactjs - Algolia 表显示不正确
问题描述
如何设置 Bootstrap 表以正确显示 Algolia 搜索结果?
我试图将 Highlights 放入 tds,但编译器不知何故认为整个返回内容只是一个单元格,而不是行。这是 React 编译器的结果:
import React, { Component } from "react";
import algoliasearch from "algoliasearch/lite";
import {
InstantSearch,
Highlight,
Hits
} from "react-instantsearch-dom";
import PropTypes from "prop-types";
import "./Algolia.css";
import { Helmet } from "react-helmet";
const searchClient = algoliasearch(
'ZL7V6958NY',
'6ccdb3835e97ced1dc5429d1f7c723a5'
);
const pageTitle = "Продавцы технической соли";
class SaltDealers extends Component {
render() {
return (
<div className="container">
<Helmet>
<title>{pageTitle}</title>
<meta
name="description"
content={pageTitle}
/>
<meta
property="og:title"
content={pageTitle}
/>
<meta name="keywords" content="соль техническая, купить техническую соль, соль техническая +в мешках, соль техническая галит, соль техническая цена" />
</Helmet>
<div className="col-md-8 ml-auto mr-auto">
<h1 className="title text-center">{pageTitle}</h1>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Company</th>
<th scope="col">Phone</th>
<th scope="col">Website</th>
<th scope="col">City</th>
<th scope="col">Amount</th>
<th scope="col">Type</th>
</tr>
</thead>
<tbody>
<InstantSearch indexName="salt_dealers" searchClient={searchClient}>
<Hits hitComponent={Hit} />
</InstantSearch>
</tbody>
</table>
</div>
);
}
}
function Hit(props) {
return (
<tr>
<th scope="row">
<Highlight attribute="company" hit={props.hit} />
</th>
<td>
<Highlight attribute="phone" hit={props.hit} />
</td>
<td>
<Highlight attribute="website" hit={props.hit} />
</td>
<td>
<Highlight attribute="city" hit={props.hit} />
</td>
<td>
<Highlight attribute="amount" hit={props.hit} /> кг
</td>
<td>
<Highlight attribute="type" hit={props.hit} />
</td>
</tr>
);
}
Hit.propTypes = {
hit: PropTypes.object.isRequired,
};
export default SaltDealers;
预期的结果是 JSX 中的一些小变化,也许我们需要一个键,但这种语法不知何故不起作用。
<tr key={ObjectID}>
解决方案
推荐阅读
- powershell - 如何使用 PowerShell 根据每个文件中的特定内容重命名文件夹中的文件?
- r - 如何拆分列中的数据以在 R 中绘制箱形图
- angular - 在 Visual Studio 2019 中创建新的 Asp.Net Core 2.1 Angular 项目时无法选择单个用户帐户
- php - 如何使用 PHP 在 FPDF 中居中表格
- c - 尝试使用 fread 读取字节但出现分段错误 11
- javascript - 如何为服务的订阅回调编写单元测试
- solr - DSE:通配符搜索
- sql - 如何在 Teradata SQL 中创建增量查询
- docker - 如何在 dockerfile 中部署动态变量供用户选择环境变量?
- r - R 从列表列表中选择所有第 N 个列表项