Semantic-ui-react:搜索结果不可见

时间:2017-11-23 12:44:27

标签: reactjs semantic-ui-react semantic-ui-css

我一直试图让搜索结果出现在语义上,但对于我的生活,我在搜索时得到的就是:

As you can see, the search results are not visible

我在index.js文件中导入了semantic-ui-css:

import "semantic-ui-css/semantic.min.css";

我正在使用超级基本数据集进行测试:

const cities = [
    {
        key: 0,
        city: "New York City",
        usState: "New York"
    },
    {
        key: 1,
        city: "San Francisco",
        usState: "California"
    },
    {
        key: 2,
        city: "Chicago",
        usState: "Illinois"
    }
];

(此数组在导入之后,但包含在上面以保持代码部分更短)

并且正在使用文档中的standard search

import React from "react";
import { Search } from "semantic-ui-react";
import _ from "lodash";

class SearchBox extends React.Component {
    state = {
        isLoading: false,
        results: [],
        value: ""
    };

    componentWillMount() {
        this.resetComponent();
    }

    resetComponent = () =>
        this.setState({ isLoading: false, results: [], value: "" });

    handleSearchChange = (e, { value }) => {
        this.setState({ isLoading: true, value });

        setTimeout(() => {
            if (this.state.value.length < 1) this.resetComponent();

            const re = new RegExp(_.escapeRegExp(this.state.value), "i");
            const isMatch = result => re.test(result.city);

            this.setState({
                isLoading: false,
                results: _.filter(cities, isMatch)
            });
        }, 500);
    };

    handleResultSelect = (e, { result }) =>
        this.setState({ value: result.city });

    render() {
        const { isLoading, results, value } = this.state;
        return (
            <div>
                <Search
                    type="text"
                    size="big"
                    loading={isLoading}
                    results={results}
                    value={value}
                    onSearchChange={this.handleSearchChange}
                    onResultSelect={this.handleResultSelect}
                />
            </div>
        );
    }
}

export default SearchBox;

我甚至尝试在编辑semantic-ui-react搜索示例时使用我的数组作为数据,但由于某种原因,结果在那里也看不到。如何使搜索结果可见?

提前感谢您的任何意见或解答!

1 个答案:

答案 0 :(得分:1)

尝试检查SearchResult的正确道具, 因为默认的SearchResult组件应该使用具有以下键之一的对象:标题,描述,价格,图像

见[https://react.semantic-ui.com/modules/search#search-example-standard][1]