阿尔及利亚表无法正确显示

时间:2019-04-10 12:43:28

标签: reactjs algolia

如何设置Bootstrap表以正确显示Algolia搜索结果?

我试图将Highlights放入tds,但是编译器为什么会认为整个返回内容只是一个单元格,而不是行。 这是React编译器的结果:

incorrect table view

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}>

0 个答案:

没有答案