table-list组件可用于商品列表,用户列表页面

需要传入一个tableHeads集合和tablebody

  1. import React from 'react';
  2.  
  3. // 通用的列表
  4. class TableList extends React.Component{
  5.     constructor(props){
  6.         super(props);
  7.         this.state = {
  8.             isFirstLoading: true
  9.         }
  10.     }
  11.     componentWillReceiveProps(){
  12.         // 列表只有在第一次挂载的时候,isFirstLoading为true,其他情况为false
  13.         this.setState({
  14.             isFirstLoading : false
  15.         });
  16.     }
  17.     render(){
  18.         // 表头信息
  19.         let tableHeader = this.props.tableHeads.map(
  20.             (tableHead, index) => {
  21.                 if(typeof tableHead === 'object'){
  22.                     return <th key={index} width={tableHead.width}>{tableHead.name}</th>
  23.                 }else if(typeof tableHead === 'string'){
  24.                     return <th key={index}>{tableHead}</th>
  25.                 }
  26.             }
  27.         );
  28.         // 列表内容
  29.         let listBody = this.props.children;
  30.         // 列表的信息
  31.         let listInfo = (
  32.             <tr>
  33.                 <td colSpan={this.props.tableHeads.length} className="text-center">
  34.                     {this.state.isFirstLoading ? '正在加载数据...' : '没有找到相应的结果~'}</td>
  35.             </tr>
  36.         );
  37.         //当listBody.length<=0,第一次加载的时候firstLoading=true,显示"正在加载数据"
  38.         //当listBody.length<=0,第一次加载的时候firstLoading=false,显示"正在加载数据"
  39.         let tableBody = listBody.length > 0 ? listBody : listInfo;
  40.         return (
  41.             <div className="row">
  42.                 <div className="col-md-12">
  43.                     <table className="table table-striped table-bordered">
  44.                         <thead>
  45.                             <tr>
  46.                                 {tableHeader}
  47.                             </tr>
  48.                         </thead>
  49.                         <tbody>
  50.                             {tableBody}
  51.                         </tbody>
  52.                     </table>
  53.                 </div>
  54.             </div>
  55.         );
  56.     }
  57. }
  58.  
  59. export default TableList;

React后台管理系统-table-list组件的更多相关文章

  1. React后台管理系统-添加商品组件

    引入了CategorySelector 二级联动组件.FileUploader图片上传组件和RichEditor富文本编辑组件 import React from 'react'; import MU ...

  2. React后台管理系统- rc-pagination分页组件封装

    1.用户列表页面使用的rc-pagination分页组件 Github地址: https://github.com/react-component/pagination 2.安装 cnpm insta ...

  3. React后台管理系统-首页Home组件

    1.Home组件要显示用户总数.商品总数和订单总数,数据请求后端的 /manage/statistic/base_count.do接口,返回的是 this.state = {            u ...

  4. 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件

    实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...

  5. 【共享单车】—— React后台管理系统开发手记:AntD Table高级表格

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  6. 【共享单车】—— React后台管理系统开发手记:AntD Table基础表格

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  7. 【共享单车】—— React后台管理系统开发手记:主页面架构设计

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  8. react后台管理系统路由方案及react-router原理解析

        最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式   ...

  9. 《React后台管理系统实战 :三》header组件:页面排版、天气请求接口及页面调用、时间格式化及使用定时器、退出函数

    一.布局及排版 1.布局src/pages/admin/header/index.jsx import React,{Component} from 'react' import './header. ...

随机推荐

  1. CCF201809(Java)

    第一题: 问题描述 在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜. 第一天,每个商店都自己定了一个价格.店主们希望自己的菜价和其他商店的一致,第二天,每一家商店都会根据他自 ...

  2. Gradle 安装(Windows)

    一.Gradle 简介 1.1 什么是 Gradle?   Gradle 是一个基于 Apache Ant 和 Apache Maven 概念的 项目自动化构建开源工具.它使用一种基于Groovy的D ...

  3. Codeforces Round #565 (Div. 3) B. Merge it!

    链接: https://codeforces.com/contest/1176/problem/B 题意: You are given an array a consisting of n integ ...

  4. 关于强大的requests

    存到文件: with open(filename, 'wb') as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) 使用 R ...

  5. tcp 三次握手,四次挥手几常见面试题

    TCP报文首部 源端口和目的端口,各占2个字节,分别写入源端口和目的端口: 序号,占4个字节,TCP连接中传送的字节流中的每个字节都按顺序编号.例如,一段报文的序号字段值是 301 ,而携带的数据共有 ...

  6. nginx中文手册内容说明

    1.什么是nginx? Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接, ...

  7. <邮件的反垃圾反病毒>

    本章——发送接收邮件的工具为雷鸟 安装 # yum install dovecot-mysql.x86_64 dovecot.x86_64 -y 编辑文件 vim 10-mail.conf mail_ ...

  8. MVVM技术 - 的实现 @{}来进行 调用那个 DataBinding方法

    new Material Design 支持哭 还有 Data Binding 结束   使用DataBindign 结束 我们很方面的实现 MVVM设计模式   什么是MVVM model 呢.   ...

  9. linq 读取xml

    xml 文件如下: <?xml version="1.0" encoding="utf-8" ?><nodes> <node> ...

  10. 阿里云部署安装redis无法访问

    ps:我在linux上安装redis后发现一直端口不通连接不上,折腾一晚上.后来在阿里云官方回复(机器人)中看到下面的回复:       2019/02/28 22:50 自己一试,过完是端口监听是本 ...