首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在ResultCard中实现onclick并将div与其他组件互换

如何在ResultCard中实现onclick并将div与其他组件互换
EN

Stack Overflow用户
提问于 2019-05-28 07:22:22
回答 2查看 333关注 0票数 0

我想要显示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内容(仍未编码)。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56333377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档