亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue深度優(yōu)先遍歷多層數(shù)組對(duì)象方式(相當(dāng)于多棵樹、三級(jí)樹)

 更新時(shí)間:2022年08月23日 10:13:23   作者:Eli-sun  
這篇文章主要介紹了vue深度優(yōu)先遍歷多層數(shù)組對(duì)象方式(相當(dāng)于多棵樹、三級(jí)樹),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

深度優(yōu)先遍歷多層數(shù)組對(duì)象

這個(gè)方法如果是對(duì)于下面的三級(jí)樹的話可以拿到爺爺Id,自己Id,父親Id;其實(shí)如果想要拿到label的話就把data.id換成data.label就行了

function treeFindPath(tree, func, path = []) {
? ? ? ? if (!tree) return []
? ? ? ? for (const data of tree) {
? ? ? ? ? path.push(data.id)
? ? ? ? ? if (func(data)) return path
? ? ? ? ? if (data.children) {
? ? ? ? ? ? const findChildren = treeFindPath(data.children, func, path)
? ? ? ? ? ? if (findChildren.length) return findChildren
? ? ? ? ? }
? ? ? ? ? path.pop()
? ? ? ? }
? ? ? ? return []
? ? ? }
? ? ? const i = treeFindPath(this.treeData, node => node.label === result)

比如樹結(jié)構(gòu)是這樣的

這相當(dāng)于是多可三級(jí)樹

?"data": [
? ? {
? ? ? "id": "1",
? ? ? "label": "能動(dòng)中心",
? ? ? "type": "1",
? ? ? "children": [
? ? ? ? {
? ? ? ? ? "id": "11",
? ? ? ? ? "label": "罐底視頻",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "111",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "四高爐6道"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "112",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "西渣罐底"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "12",
? ? ? ? ? "label": "煤氣柜站",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "121",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "13號(hào)道口02"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "122",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "13號(hào)道口01"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "123",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "能動(dòng)中心樓頂"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "13",
? ? ? ? ? "label": "能動(dòng)中心樓頂",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "131",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "44455666"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? },
? ? {
? ? ? "id": "2",
? ? ? "label": "煉鐵廠",
? ? ? "type": "1",
? ? ? "children": [
? ? ? ? {
? ? ? ? ? "id": "21",
? ? ? ? ? "label": "星云智聯(lián)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "211",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "程控樓3樓"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "212",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "程控樓1樓過道西側(cè)"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "213",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "程控樓2樓大廳"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "214",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "公司主樓5樓西側(cè)"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "22",
? ? ? ? ? "label": "翻車機(jī)溜車線區(qū)域",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "221",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "煉鋼球罐全貌1"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "23",
? ? ? ? ? "label": "焦化化產(chǎn)作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "231",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "4#萬立儲(chǔ)槽全貌"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "232",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "4#萬立中壓氧壓機(jī)"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "233",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "4#萬立變電所低壓室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? },
? ? {
? ? ? "id": "3",
? ? ? "label": "煉鋼廠",
? ? ? "type": "1",
? ? ? "children": [
? ? ? ? {
? ? ? ? ? "id": "31",
? ? ? ? ? "label": "熔融金屬及吊運(yùn)區(qū)域",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "311",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "8號(hào)吊點(diǎn)鞍馬座"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "312",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "8號(hào)起吊點(diǎn)右"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "32",
? ? ? ? ? "label": "區(qū)域監(jiān)控",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "321",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "測(cè)試點(diǎn)33"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "322",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "原料跨1"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "323",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "板坯LH釩鐵柜"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "33",
? ? ? ? ? "label": "罐號(hào)識(shí)別",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "331",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "修罐間東頭"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? },
? ? {
? ? ? "id": "4",
? ? ? "label": "冷軋廠",
? ? ? "type": "1",
? ? ? "children": [
? ? ? ? {
? ? ? ? ? "id": "41",
? ? ? ? ? "label": "軋鋼作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "411",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "軋機(jī)主控室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "42",
? ? ? ? ? "label": "普冷作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "421",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "原料庫1"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "422",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "原料庫2"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "43",
? ? ? ? ? "label": "鍍鋅作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "431",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "生產(chǎn)運(yùn)行檢測(cè)"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "432",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "軋機(jī)高壓室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "44",
? ? ? ? ? "label": "點(diǎn)檢維護(hù)作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "441",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "退火爐4"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "442",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "退火爐1"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? }
? ]

vue遍歷包含數(shù)組的對(duì)象

最近開發(fā)自己博客,在遍歷對(duì)象類型數(shù)據(jù)時(shí)候,怎么也拿不到,嘗試過兩層遍歷都不行,最終利用巧計(jì)解決了,記錄下來:

請(qǐng)求來拿到后數(shù)據(jù)格式是下面這種

data(){
? ? return{
? ? ? noticeList:{
? ? ? ? notice:["aaaaa","bbbb","cccc"],
? ? ? ? times:[1564707990252,1564708337658,1564707990252]
? ? ? },
? ? }
? },

最終在html中這樣遍歷

<li v-for="(text,index) in noticeList.notice" :key="index">
? {{text}}<span>{{noticeList.times[index] | formatDate}}</span>
</li>

最重要的一點(diǎn)是要對(duì)象中兩個(gè)數(shù)組的index對(duì)應(yīng)的值是相對(duì)應(yīng)的值。遍歷對(duì)象中其中一個(gè)數(shù)組,另外一個(gè)數(shù)組用遍歷過程中的index來獲取其中對(duì)應(yīng)的值,非常巧妙的一個(gè)辦法。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論