摘要:表頭設(shè)計原理和多叉樹的原理類似,參考了它的展示形式。大家一起交流成長。
1. 表頭設(shè)計
原理:
和多叉樹的原理類似,參考了它的展示形式。
表頭說明:
如果沒有孩子節(jié)點就只返回如下一個字段:
name :名字
如果有孩子節(jié)點,就把數(shù)據(jù)加在children里面,層層嵌套,返回字段如下:
name :名字
children : 孩子節(jié)點
數(shù)據(jù)結(jié)構(gòu)格式,參考如下代碼:
headerData:[ { name: "地區(qū)", }, { name: "總數(shù)據(jù)", children: [ { name: "數(shù)據(jù)1", children: [ { name: "數(shù)據(jù)11", children: [ { name: "數(shù)據(jù)111", }, { name: "數(shù)據(jù)112", } ] }, { name: "數(shù)據(jù)12", children: [ { name: "數(shù)據(jù)121", }, { name: "數(shù)據(jù)122", } ] }, { name: "數(shù)據(jù)13", children: [ { name: "數(shù)據(jù)131", }, { name: "數(shù)據(jù)132", } ] }, { name: "數(shù)據(jù)14", }, ] } ] } ];
表頭的寬高方面,前端計算,后端不用管,按照如下格式返回數(shù)據(jù)即可。
2. 表格數(shù)據(jù)格式每一項按照表頭展示的順序返回,通過數(shù)組的形式
返回一個參數(shù):
bodyData:總數(shù)據(jù)
數(shù)據(jù)結(jié)構(gòu)格式參考代碼如下:
bodyData:[ ["地區(qū)最先","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ["地區(qū)最后","數(shù)據(jù)111","數(shù)據(jù)112","數(shù)據(jù)121","數(shù)據(jù)122","數(shù)據(jù)131","數(shù)據(jù)132","數(shù)據(jù)14"], ]3. 效果
如上表頭與表格數(shù)據(jù)代碼生成的效果如圖:
語法高亮用到 codemirror 插件
/** * 遞歸遍歷 格式化數(shù)組 * @param { Array } paramArr 目標數(shù)組 * @param { Number } level 層級 */ export function formatArray(paramArr, level) { let levelFirst = Number(level) const arr = [] let childArr = [] for (let i = 0; i < paramArr.length; i++) { let obj = {} for (let j in paramArr[i]) { if (j != "children") { obj[j] = paramArr[i][j] } obj["level"] = levelFirst obj["width"] = getLeafCountTree(paramArr[i]) if (!paramArr[i].children) { obj["childrenNumber"] = 0 // LeafNode: 葉子節(jié)點就是樹中最底段的節(jié)點 // obj["isLeafNode"] = true } else { // obj["isLeafNode"] = false obj["childrenNumber"] = paramArr[i].children.length } } arr.push(obj) if (paramArr[i].children) { let lev = Number(levelFirst) + 1 childArr = childArr.concat(formatArray(paramArr[i].children, lev)); } } let endArr = arr.concat(childArr) return endArr }
/** * 獲取 節(jié)點的所有葉子節(jié)點個數(shù) * @param {Object} json Object對象 */ export function getLeafCountTree(json) { if(!json.children){ return 1; }else{ var leafCount = 0; for(var i = 0 ; i < json.children.length ; i++){ leafCount = leafCount + getLeafCountTree(json.children[i]); } return leafCount; } }
// json對對象字符串的格式化,美化 export function jsonFromat (text_value){ if(text_value == ""){ alert("不能為空"); return false; } else { var json=eval("(" + text_value + ")"); text_value=JSON.stringify(json); var res=""; for(var i=0,j=0,k=0,ii,ele;i 5. 效果鏈接:復雜表頭 json 數(shù)據(jù)格式驗證:
{{l.name}} {{ x | valueFromt }} 提交 效果鏈接如下:
復雜表格設(shè)計數(shù)據(jù)格式
動態(tài)效果:
最后對 全棧開發(fā) 有興趣的朋友可以掃下方二維碼關(guān)注我的公眾號 —— 愛寫bugger的阿拉斯加
分享 web 開發(fā)相關(guān)的技術(shù)文章,熱點資源,全棧程序員的成長之路。
大家一起交流成長。
只要關(guān)注公眾號并回復 福利 便送你六套視頻資源: Python、Java、Linux、Go、vue、react、javaScript
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/96361.html
摘要:下的表格狂想曲前言歡迎大家閱讀從零開始的組件開發(fā)之路系列第一篇,表格篇。北京小李中的每一個元素是一列的配置,也是一個對象,至少應該包括如下幾部分表頭該列使用行中的哪個進行顯示易用性與通用性的平衡易用性與通用性互相制衡,但并不是絕對矛盾。 React 下的表格狂想曲 0. 前言 歡迎大家閱讀「從零開始的 React 組件開發(fā)之路」系列第一篇,表格篇。本系列的特色是從 需求分析、API 設(shè)...
摘要:遵循特定規(guī)則,利用操作符,終止節(jié)點和其他非終止節(jié)點,構(gòu)造新的字符串非終結(jié)符是表示字符串的樹的內(nèi)部節(jié)點。語法中的生產(chǎn)具有這種形式非終結(jié)符終結(jié),非終結(jié)符和運算符的表達式語法的非終結(jié)點之一被指定為根。 大綱 基于狀態(tài)的構(gòu)建 基于自動機的編程 設(shè)計模式:Memento提供了將對象恢復到之前狀態(tài)的功能(撤消)。 設(shè)計模式:狀態(tài)允許對象在其內(nèi)部狀態(tài)改變時改變其行為。 表驅(qū)動結(jié)構(gòu)* 基于語法的構(gòu)...
摘要:是的擴展格式和缺省的數(shù)據(jù)庫引擎。數(shù)據(jù)庫引擎都是造就靈活性的技術(shù)的直接產(chǎn)品,這項技術(shù)就是。估計這個插件式數(shù)據(jù)庫引擎的模型甚至能夠被用來為創(chuàng)建本地的提供器。能夠讓你在表格這一層指定數(shù)據(jù)庫引擎,所以它們有時候也指的是。 數(shù)據(jù)庫引擎介紹MySQL數(shù)據(jù)庫引擎取決于MySQL在安裝的時候是如何被編譯的。要添加一個新的引擎,就必須重新編譯MYSQL。在缺省情況下,MYSQL支持三個引擎:ISAM、M...
閱讀 3943·2021-09-22 10:02
閱讀 3371·2019-08-30 15:52
閱讀 3064·2019-08-30 12:51
閱讀 759·2019-08-30 11:08
閱讀 2069·2019-08-29 15:18
閱讀 3110·2019-08-29 12:13
閱讀 3598·2019-08-29 11:29
閱讀 1876·2019-08-29 11:13