React实现疫情情况列表展示

准备工作

在前面学习了React的基础知识以后此篇博客讲解的是如何通过使用React的基础语法来模拟从后端或者是爬虫获取到json数据进行基础的显示,并利用公司提供的前端组件组件地址进行渲染处理(组件依赖安装等查看网站有具体信息)。

Json数据可以搜索网易疫情地图,进入控制台点击network,选中XHR列查看数据,将整个json数据拷贝到自己的工程目录中,然后在index.js中进行引用:import jsonData from './list-total.json'

image-20200730144848427

具体实现

import React, { Component} from 'react';
import ReactDOM from 'react-dom';
import jsonData from './list-total.json'
import { Table } from 'tinper-bee';
import 'bee-table/build/Table.css';
/**
 * 这部分学习的是React 来展示地图信息
 */
console.log(jsonData)
let allworldObj ={
    // 就是相当于先新定义一个对象。
}
jsonData.data.areaTree.forEach((item,i)=>{
    // 
    if(allworldObj[item.name]==undefined){
         /** 
     * 用来判断是否真的存在 因为我们看到有些值的定义是undefined 
     * 需要先进行一个初始化
     *  */
        allworldObj[item.name] ={
            confirm:0,
            suspect:0,
            heal:0,
            dead:0
        }
    }
   /**
    * 对于一些值为null的存在,也要进行初始化。
    */
    item.today.confirm= item.today.confirm? item.today.confirm:0;
    item.today.suspect= item.today.suspect? item.today.suspect:0;
    item.today.heal = item.today.heal? item.today.heal: 0;
    item.today.dead=item.today.dead?item.today.dead:0;
    allworldObj[item.name] = {
        // 对信息进行统计处理 计算: 等于当前的值加上新获取到的值。
        confirm:allworldObj[item.name].confirm+item.today.confirm,
        suspect:allworldObj[item.name].suspect+ item.today.suspect,
        heal: allworldObj[item.name].heal+ item.today.heal,
        dead: allworldObj[item.name].dead+item.today.dead
    }
});
let allList =[]// 定义一个空的数组
for (const key in allworldObj) {
    allworldObj[key].name =key
    //  将信息的名字也加载到里面
    allList.push(allworldObj[key])
}
allList.sort((a,b)=>{
    // 顺序排列 
   return   a.confirm<b.confirm?1:-1
})
console.log(allList)
function ListItem(props){
    /**
     * 利用平台提供的组件
     * import { Table } from 'tinper-bee';
     * 导入表格信息。
     *  */ 
const columns = [
    {title: "序号",dataIndex: "index",key: "index",width: 80},
    {title: "国家名称",dataIndex: "orderCode",key: "orderCode",width: 200},
    {title: "确诊人数",dataIndex: "supplierName",key: "supplierName",width: 200},
    {title: "成功治愈",dataIndex: "type_name",key: "type_name",width: 200},
    {title: "怀疑人数",dataIndex: "purchasing",key: "purchasing",width: 200},
    {title: "死亡人数:",dataIndex: "purchasingGroup",key: "purchasingGroup",width: 200},
  ];
  const data = [
    { 
      index:props.index+1,
      orderCode: props.data.name, 
      supplierName: props.data.confirm,
      type_name: props.data.heal,
      purchasing:props.data.suspect, 
      purchasingGroup:props.data.suspect,
      key:'1'
    }
  ];
    return(
        <Table 
        className="demo" 
        columns={columns} 
        data={data} />
    )
}
class Bll extends React.Component{
    constructor(props){
        super(props)
    }
    render(){
        let WorldList = this.props.list.map((item,index)=>{
            return(
                <ListItem key ={index} data={item} index={index}></ListItem>
            )
        });
        return(
            <div>
                <h1>全球病理</h1>   
                    {WorldList}    
            </div>
        )
    }
}   
ReactDOM.render(
    <Bll list={allList}/>,
    document.querySelector('#root')
)

成果展示:

image-20200730151708672

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值