简体   繁体   English

使用ReactTable时,如何将该URL更改为该代码中的链接?

[英]How can I change this url to a link in that code when using ReactTable?

Here is React code: 这是React代码:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import ReactTable from 'react-table';
import _ from 'lodash';
import './style.css';

class GithubDataTable extends Component {
  render() {
    const { showData, savedData } = this.props;
    let data = null;

    if (showData === 'last') {
      data = _.last(savedData);
    } else {
      data = savedData[showData];
    }

    console.log(data);

    return (
      <div>
        {data && (
          <ReactTable
            data={data.items}
            columns={[
              {
                Header: 'Data from GitHub',
                columns: [
                  {
                    Header: 'Id',
                    id: 'id',
                    accessor: d => d.id,
                  },
                  {
                    Header: 'Repo Title',
                    id: 'repoTitle',
                    accessor: d => d.name,
                  },
                  {
                    Header: 'Owner',
                    id: 'owner',
                    accessor: d => d.owner.login,
                  },
                  {
                    Header: 'Link',
                    id: 'link',
                    accessor: d => d.html_url, // example data string "https://github.com/Michaelcj10/ReactJS-GitHub-User-Finder-App"
                  },
                  {
                    Header: 'Created at',
                    id: 'createdAt',
                    accessor: d => d.created_at.slice(0, 10),
                  },
                  {
                    Header: 'Updated at',
                    id: 'updatedAt',
                    accessor: d => d.updated_at.slice(0, 10),
                  },
                  {
                    Header: 'Stars',
                    id: 'stars',
                    accessor: d => d.stargazers_count,
                  },
                  {
                    Header: 'Forks',
                    id: 'forks',
                    accessor: d => d.forks_count,
                  },
                ],
              },
            ]}
            defaultPageSize={10}
            pageSizeOptions={[5, 10, 15, 20]}
            className="-striped -highlight"
          />
        )}
      </div>
    );
  }
}

function mapStateToProps(state) {
  return {
    savedData: state.savedData,
    showData: state.showData,
  };
}
export default connect(mapStateToProps, null)(GithubDataTable);

And I have problem with that particular element: 我对此特定元素有疑问:

{
                    Header: 'Link',
                    id: 'link',
                    accessor: d => d.html_url, // https://github.com/Michaelcj10/ReactJS-GitHub-User-Finder-App
                  },

在此处输入图片说明

Data is shown as text, but how can I add html in that particular situation to this JSX to obtain a link 数据显示为文本,但是如何在特定情况下向JSX添加html以获取链接

Not enought text hack: 没有足够的文字技巧:


It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. 早已确定的事实是,在查看页面布局时,读者会被页面的可读内容分散注意力。 The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters... 使用Lorem Ipsum的要点是它具有或多或少的字母正态分布...

Looks like you might be able to use the Cell property to display custom markup: 看起来您可能可以使用Cell属性显示自定义标记:

{
    Header: 'Link',
    id: 'link',
    accessor: d => d.html_url, // https://github.com/Michaelcj10/ReactJS-GitHub-User-Finder-App
    Cell: props => <a href={props.value}>{props.value}</a>
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM