首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以使用react-window来显示带有按钮的项目列表吗?

可以使用react-window来显示带有按钮的项目列表吗?
EN

Stack Overflow用户
提问于 2021-08-02 11:41:22
回答 1查看 122关注 0票数 0

我需要知道是否可以使用react-window来显示项目列表,并在同一行中显示每个按钮的操作。如果是,请给我一个提示如何做。

代码语言:javascript
复制
import React from "react";

import { FixedSizeList as List } from "react-window";

const ListBebes = ({
  bebes,
  handleItemClick,
  handleEditClick,
  handleDeleteClick,
}) => {
  const Row = ({ index, style }) => (
    <div className={index % 2 ? "ListItemOdd" : "ListItemEven"} style={style}>
      {bebes[index].nombres}
    </div>
  );
  return (
    <List
      className="List"
      height={5}
      itemCount={bebes.length}
      itemSize={35}
      width={300}
    >
      Row
    </List>
  );
};

export default ListBebes;

代码语言:javascript
复制
<Col xs="4">
  {this.state.is_fetching ? (
    "Loading..."
  ) : (
    <ListBebes
      bebes={this.state.bebes}
      handleItemClick={(id) => this.handleItemClick(id)}
      handleEditClick={(id) => this.handleEditClick(id)}
      handleDeleteClick={(id) => this.handleDeleteClick(id)}
    ></ListBebes>
  )}
</Col>;

EN

回答 1

Stack Overflow用户

发布于 2021-08-02 13:14:52

在Row函数中添加您想要的内容

代码语言:javascript
复制
const Row = ({ index, style }) => (
   <div>
      <div className={index % 2 ? "ListItemOdd" : "ListItemEven"} style={style}>
        {bebes[index].nombres}
      </div>
      <button>Your Button Here!</button>
   </div> 
);

或者只是导入一个新组件,可能是<YourItemComponent />,然后在行中返回它,您可以像其他组件一样在新组件中执行您想要的操作

代码语言:javascript
复制
const Row = ({index, style}) => (<YourItemComponent index={index} style={style}/>); 

很抱歉我的英语很差,希望你能理解

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

https://stackoverflow.com/questions/68620983

复制
相关文章

相似问题

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