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. POJ1034 The dog task

    题目来源:http://poj.org/problem?id=1034 题目大意: 一个猎人在遛狗.猎人的路径由一些给定的点指定.狗跟随着猎人,要与主人同时到达那些指定的点.在丛林里有一些有趣的地方, ...

  2. Python Unittest - Test Fixtures 测试夹具

    一.什么是测试夹具 定义单个或者多个测试所需的环境准备(setUp),以及环境清理(tearDown). 例:连接数据库,或者创建Selenium WebDriver driver实例 二.测试夹具有 ...

  3. D. Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D D. Beautiful numbers time limit per test 4 second ...

  4. mybatis使用说明

    起步:1.创建一个maven项目工程.2.打开pom.xml配置文件,3.设置源代码编码方式为UTF-8.4.设置编译源代码的JDK版本.最好大于1.6版本.5. 重点--添加Mybatis的相关依赖 ...

  5. (转)IE6 死后即将大快人心的10件事

    (转)未来五年程序员应当具备的十项技能 W3C CSS 2.1 Specification(Quick Table of Contents) (转)IE6 死后即将大快人心的10件事 2009-04- ...

  6. aspx有"记住我"的登录

    客户端 <form id="form1" runat="server"> <div> 用户名:<input type=" ...

  7. webpack.config.js====配置babel

    参考:https://www.jianshu.com/p/9808f550c6a91. 安装依赖babel-loader: 负责 es6 语法转化babel-preset-env: 包含 es6.7 ...

  8. JavaSE_3_面向对象

    1.wait方法底层原理 wait是object中的方法,可以暂停线程,会释放对象锁,不像sleep方法,线程休眠期依然持有锁,通过调用notify或notifyAll方法唤醒线程. lock.wai ...

  9. springboot 学习笔记(九)

    springboot整合activemq,实现broker集群部署(cluster) 1.为实现jms高并发操作,需要对activemq进行集群部署,broker cluster就是activemq自 ...

  10. mysql5.6.31安装及配置

    1,下载安装包解压到安装位置.下载地址https://dev.mysql.com/downloads/mysql/5.6.html#downloads 2,修改默认配置文件 在根目录下面有my-def ...