本文介绍了ReactJs实现树形结构的数据显示的组件的示例,分享给大家,具体如下:
1、该组件树形显示数据
2、组件中数据的请求方式为fetch方式
3、点击对应的数据前面的小三角,fetch请求改数据下对应的子数据,并展开该节点。
4、将该组件的js、less文件放到kpiTree目录下,在kpiTree目录下创建images目录将组件需要的图片放入给目录,在kpiTree目录下创建json文件夹将该组件需要的json文件放入改文件夹中,组件便可正常运行。
kpiTree.js文件
/** * Created by Administrator on 2017/3/20 0020. */ import React,{Component} from "react" import "./kpiTree.less"; export default class KpiTree extends Component{ constructor(props){ super(props); this.state={ } this._handleSelect=this._handleSelect.bind(this); this._handleSearch=this._handleSearch.bind(this); this._handleReturn=this._handleReturn.bind(this); } _handleSearch=()=>{ debugger var _self=this; var _inputValue=this.refs.ksearchInput.value;//搜索框输入的关键字 var _main=this.refs.kpiTree; _main.innerHTML=""; var searchListUrl = '../src/kpiTree/json/searchListData.json'; fetch(searchListUrl,{ credentials:'same-origin', async:false, //method: 'POST', method: 'GET', mode:'cors',//跨域请求 headers: { "Content-type": "application/x-www-form-urlencoded", "User-Agent": " Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36" }, }) .then(function(res) { console.log("Response succeeded", JSON.stringify(res.ok)); return res.json(); }) .then(function(data) { debugger _self._renderTreeNode(_main,data,0); }) .catch(function(e) { console.log("fetch fail",e.toString()); }); } _handleReturn=()=>{ this.refs.ksearchInput.value="";//清空搜索输入框 var _main=this.refs.kpiTree; _main.innerHTML=""; this._fetchTreeNodeData("",_main,0); } _handleSelect=()=>{ debugger; var _select=[]; $(this.refs.kpiTree).find("input:checkbox").each(function() {//$('#kpiTree input:checkbox') if ($(this)[0].pid!=undefined&&$(this)[0].checked ==true) { var _selected_kpi={}; _selected_kpi.kid=$(this)[0].parentNode.id.substring(4); _selected_kpi.kname=$(this)[0].parentNode.children[1].innerHTML _selected_kpi.pid=$(this)[0].parentNode.pid.substring(4); _select.push(_selected_kpi); } }); this.props.callbackParent(_select); } componentDidMount=()=>{ var _main=this.refs.kpiTree; this._fetchTreeNodeData("",_main,0); } _selectAllCheckBox=(parentNodeId,event)=>{ var _items=$("#" + parentNodeId+" input") for(var i=0;i<_items.length;i++){ if (_items[i].pid!=undefined&&_items[i].pid==parentNodeId){ _items[i].checked=event.currentTarget.checked; } } } _renderTreeNode=(nodeObj,treeData,paddingLeft)=>{ var _self=this; var hasAllSelectBox=false; if(treeData.length>0){ for(var i=0;i<treeData.length;i++){ if(treeData[i].hasChild=="0"){ hasAllSelectBox=true } } var _node=treeData.map((data,index)=>{ var _kname=data.kname; var _div=document.createElement("div"); _div.pid="node"+data.pid; _div.id="node"+data.kid; _div.style.paddingLeft=paddingLeft+"px"; var _img=document.createElement("img"); _img.src="/UploadFiles/2021-04-02/hide.png">kpiTree.less文件
.kpitree_panel{ position: relative; width:308px; background-color: #F2F2F2; border: 1px solid #cfcfcf ; } .kpitree_panel_height_01{ height: 548px; } .kpitree_panel_height_02{ height: 378px; } .ksearch-div{ position: relative; top: 10px; margin-left: 4px; width: 310px; height: 30px; } .ksearch-input{ border: 1px; width: 145px; height: auto; border-radius: 10px; } .ksearch-icon{ position: relative; left: -24px; width: 17px; height: 17px; } .ksearch-button{ position: relative; left: 150px; top: -22px; font-size: 12px; color: #999999; padding-top: 3px; text-align: center; cursor: pointer; width: 40px; height:24px; border: solid 0.8px #CBCBCB ; -webkit-border-radius: 8px; } .kreturn-button{ position: relative; left: 171px; top: -22px; font-size: 12px; color: #999999; padding-top: 3px; text-align: center; cursor: pointer; width: 40px; height: 24px; border: solid 0.8px #CBCBCB; -webkit-border-radius: 8px; } .kselecte-button{ position: relative; left: 226px; top: -46px; font-size: 12px; color: #999999; padding-top: 3px; text-align: center; cursor: pointer; width: 60px; height: 25px; border: solid 0.8px #CBCBCB; -webkit-border-radius: 8px; background-color: #F2F2F2; } .kbottom-content{ padding: 10px; color: #999999; margin-left: 13px; overflow-y: scroll; overflow-x: hidden; width: 280px; margin-top: 20px; background-color: #F7F7F7; } .kbottom-content_height_01{ height: 480px; } .kbottom-content_height_02{ height: 318px; } .knode-hide-show-icon{ width: 10px; height: 10px; cursor: pointer; }下面这些json文件都放入json文件夹中
treeListData.json文件
[ {"kid":"01","kname":"综合指标","hasChild":"1","pid":"-1"}, {"kid":"02","kname":"分析类指标","hasChild":"1","pid":"-1"}, {"kid":"03","kname":"组合指标","hasChild":"1","pid":"-1"}, {"kid":"04","kname":"移动业务计费收入","hasChild":"1","pid":"-1"}, {"kid":"05","kname":"2G业务","hasChild":"1","pid":"-1"} ]treeListData01.json文件
[ {"kid":"010","kname":"综合指标1","hasChild":"1","pid":"01"}, {"kid":"011","kname":"分析类指标1","hasChild":"1","pid":"01"}, {"kid":"012","kname":"组合指标1","hasChild":"1","pid":"01"}, {"kid":"013","kname":"移动业务计费收入1","hasChild":"1","pid":"01"}, {"kid":"014","kname":"2G业务1","hasChild":"1","pid":"01"} ]treeListData010.json文件
[ {"kid":"0100","kname":"综合指标000","hasChild":"0","pid":"010"}, {"kid":"0101","kname":"分析类指标000","hasChild":"0","pid":"010"}, {"kid":"0102","kname":"组合指标000","hasChild":"0","pid":"010"}, {"kid":"0103","kname":"移动业务计费收入000","hasChild":"0","pid":"010"}, {"kid":"0104","kname":"2G业务000","hasChild":"0","pid":"010"} ]searchListData.json文件
[ {"kid":"01","kname":"综合指标","hasChild":"0","pid":"-1"}, {"kid":"02","kname":"分析类指标","hasChild":"0","pid":"-1"}, {"kid":"03","kname":"组合指标","hasChild":"0","pid":"-1"}, {"kid":"04","kname":"移动业务计费收入","hasChild":"0","pid":"-1"}, {"kid":"05","kname":"2G业务","hasChild":"0","pid":"-1"}, {"kid":"01","kname":"综合指标","hasChild":"0","pid":"-1"}, {"kid":"02","kname":"分析类指标","hasChild":"0","pid":"-1"}, {"kid":"03","kname":"组合指标","hasChild":"0","pid":"-1"}, {"kid":"04","kname":"移动业务计费收入","hasChild":"0","pid":"-1"}, {"kid":"05","kname":"2G业务","hasChild":"0","pid":"-1"}, {"kid":"01","kname":"综合指标","hasChild":"0","pid":"-1"}, {"kid":"02","kname":"分析类指标","hasChild":"0","pid":"-1"}, {"kid":"03","kname":"组合指标","hasChild":"0","pid":"-1"}, {"kid":"04","kname":"移动业务计费收入","hasChild":"0","pid":"-1"}, {"kid":"05","kname":"2G业务","hasChild":"0","pid":"-1"}, {"kid":"01","kname":"综合指标","hasChild":"0","pid":"-1"}, {"kid":"02","kname":"分析类指标","hasChild":"0","pid":"-1"}, {"kid":"03","kname":"组合指标","hasChild":"0","pid":"-1"}, {"kid":"04","kname":"移动业务计费收入","hasChild":"0","pid":"-1"}, {"kid":"05","kname":"2G业务","hasChild":"0","pid":"-1"} ]树组件运行后的结果:
搜索结果:(这里是请求了一个json文件的数据,在实际的交互中可根据自己输入的名称去请求后台对应的数据即可)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]