我想要显示ResultCard中用户点击内容的详细信息。
当用户单击结果卡中的url时,我想根据在我的elastic search cluster(res)中找到的结果,用呈现的html替换div内容(当前显示的结果)。
我尝试添加onclick属性,但什么也没有发生。Reactivesearch文档不会列出此属性。
当然,我可以在ResultCard的url属性中传递参数,并将用户重定向到另一个页面,但页面将完全重新加载(使用index.js中定义的菜单和页脚)
我认为在div中创建具有状态镜像当前显示的子组件的父组件是可行的。
但是,当用户单击结果卡时,如何运行javascript来设置状态呢?
import React, { Component } from 'react';
import { ReactiveBase, CategorySearch, SingleRange, ResultCard } from '@appbaseio/reactivesearch';
class App extends Component {
render() {
return (
<ReactiveBase
app="artists"
url="https://admin:xxxxxxx@node1.searchevolution.com:9200"
type="_doc">
<div style={{ display: "flex", "flexDirection": "row" }}>
<div style={{ display: "flex", "flexDirection": "column", "width": "40%" }}>
<CategorySearch
componentId="searchbox"
dataField="nom"
categoryField="occupations.keyword"
type="artists"
placeholder="Search for Artists, Painter, Sculptor, Photographs"
style={{
padding: "5px",
"marginTop": "10px"
}}
/>
</div>
<ResultCard
componentId="result"
dataField="nom"
title="Results"
from={0}
size={6}
pagination={true}
onclick="alert('Message à afficher');"
react={{
and: ["searchbox"]
}}
onData={(res) => {
return {
image: "data:image/png;base64,iVBORw0KGgoA",
title: res.occupations,
description: res.nom,
url: "/details/" + res
}
}}
style={{
"width": "60%",
"textAlign": "center"
}}
/>
</div>
</ReactiveBase>
);
}
}
export default App;
预期的结果是使用来自另一个组件的呈现html更改div内容(仍未编码)。
https://stackoverflow.com/questions/56333377
复制相似问题