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. MySQL的高可用实现:MySQL系列之十四

    MySQL的高可以有三种实现方式:多主模式(Multi Master MySQL),MHA(Master High Availability)和 Galera Cluster:wresp 一.MHA ...

  2. CF616D Longest k-Good Segment

    题目描述 给定一个包含\(n\)个整数的序列\(a\),\(0\le a_i \le 10^6\),询问不重复数字个数\(\le k\)的最长区间的左右端点.如果有多解输出任意一组. 输入输出格式 输 ...

  3. 微信小程序在sublime开发代码高亮显示

    问题:xxx.wxml 和xxx.wxss在subline中不高亮不显示 如下图,开发起来非常的不方便 解决办法:右下角将Plain Text改为Html,问题解决,可高亮,提高代码可读性,可提示,提 ...

  4. Linux下iptables总结

    linux下防火墙iptables 工作于网络或主机边缘,对进出本网络或本主机的网络报文安装事先设定好的匹配规则进行检查,对能够被规则所匹配的报文按照规则定义的处理机制进行处理的组件 通常情况下ipt ...

  5. hutool java工具架包功能介绍

    https://blog.csdn.net/lx1309244704/article/details/76459718

  6. An internal error occurred during: "Add Deployment". Container with path org.eclipse.jdt.launching.

    导入非本机项目出现这种错误,原因就是JDK版本不一致. 具体解决步骤如下: 右键项目名→Properties→JavaBuild Path→Libraries→选中JRE SystemLibrary[ ...

  7. SpringMVC(二)高级应用

    一.参数绑定-----集合类型 二.数据回显(例如提交表单失败了,数据没有丢失) 三.上传图片 四.json数据的交互 五.restful 支持 六.拦截器

  8. (转)linux正则表达式详解

    linux正则表达式详解 http://blog.csdn.net/wuliowen/article/details/64131815 1:什么是正则表达式: 简单的说,正则表达式就是处理字符串的方法 ...

  9. (转)Linux 命令(40): wc 命令

    Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 原文:http://blog.jobbole.com/109925/ http:/ ...

  10. android 开发-数据存储之文件存储

    android的文件存储是通过android的文件系统对数据进行临时的保存操作,并不是持久化数据,例如网络上下载某些图片.音频.视频文件等.如缓存文件将会在清理应用缓存的时候被清除,或者是应用卸载的时 ...