最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

這個方法如果是對于下面的三級樹的話可以拿到爺爺Id,自己Id,父親Id;其實如果想要拿到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)

比如樹結構是這樣的

這相當于是多可三級樹

?"data": [
? ? {
? ? ? "id": "1",
? ? ? "label": "能動中心",
? ? ? "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號道口02"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "122",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "13號道口01"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "123",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "能動中心樓頂"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "13",
? ? ? ? ? "label": "能動中心樓頂",
? ? ? ? ? "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樓過道西側"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "213",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "程控樓2樓大廳"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "214",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "公司主樓5樓西側"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "22",
? ? ? ? ? "label": "翻車機溜車線區(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#萬立儲槽全貌"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "232",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "4#萬立中壓氧壓機"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "233",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "4#萬立變電所低壓室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? },
? ? {
? ? ? "id": "3",
? ? ? "label": "煉鋼廠",
? ? ? "type": "1",
? ? ? "children": [
? ? ? ? {
? ? ? ? ? "id": "31",
? ? ? ? ? "label": "熔融金屬及吊運區(qū)域",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "311",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "8號吊點鞍馬座"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "312",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "8號起吊點右"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "32",
? ? ? ? ? "label": "區(qū)域監(jiān)控",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "321",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "測試點33"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "322",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "原料跨1"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "323",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "板坯LH釩鐵柜"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "33",
? ? ? ? ? "label": "罐號識別",
? ? ? ? ? "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": "軋機主控室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "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)運行檢測"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "432",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "軋機高壓室"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? },
? ? ? ? {
? ? ? ? ? "id": "44",
? ? ? ? ? "label": "點檢維護作業(yè)區(qū)",
? ? ? ? ? "type": "2",
? ? ? ? ? "children": [
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "441",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "退火爐4"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? "id": "442",
? ? ? ? ? ? ? "type": "3",
? ? ? ? ? ? ? "label": "退火爐1"
? ? ? ? ? ? }
? ? ? ? ? ]
? ? ? ? }
? ? ? ]
? ? }
? ]

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

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

請求來拿到后數(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>

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

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

相關文章

  • 解讀vue項目防范XSS攻擊問題

    解讀vue項目防范XSS攻擊問題

    這篇文章主要介紹了解讀vue項目防范XSS攻擊問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • vue單頁面在微信下只能分享落地頁的解決方案

    vue單頁面在微信下只能分享落地頁的解決方案

    這篇文章主要介紹了vue單頁面在微信下只能分享落地頁的解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • vue flex 布局實現(xiàn)div均分自動換行的示例代碼

    vue flex 布局實現(xiàn)div均分自動換行的示例代碼

    這篇文章主要介紹了vue flex 布局實現(xiàn)div均分自動換行,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • vuex中...mapstate和...mapgetters的區(qū)別及說明

    vuex中...mapstate和...mapgetters的區(qū)別及說明

    這篇文章主要介紹了vuex中...mapstate和...mapgetters的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue-Element-Admin集成自己的接口實現(xiàn)登錄跳轉

    Vue-Element-Admin集成自己的接口實現(xiàn)登錄跳轉

    關于這個Vue-element-admin中的流程可能對于新的同學不是很友好,所以本文將結合實例代碼,介紹Vue-Element-Admin集成自己的接口實現(xiàn)登錄跳轉,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 關于vue組件事件屬性穿透詳解

    關于vue組件事件屬性穿透詳解

    今天小編就為大家分享一篇關于vue組件事件屬性穿透詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vue3+vite+vant項目下按需引入vant報錯Failed?to?resolve?import的原因及解決方案

    vue3+vite+vant項目下按需引入vant報錯Failed?to?resolve?import的原因及解決

    這篇文章主要給大家介紹了關于vue3+vite+vant項目下按需引入vant報錯Failed?to?resolve?import的原因及解決方案,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-01-01
  • 詳解在vue-cli中使用graphql即vue-apollo的用法

    詳解在vue-cli中使用graphql即vue-apollo的用法

    這篇文章主要介紹了詳解在vue-cli中使用graphql即vue-apollo的用法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • vue中如何防止用戶頻繁點擊按鈕詳解

    vue中如何防止用戶頻繁點擊按鈕詳解

    在后臺使用過程中經(jīng)常會因為按鈕重復點擊,而造成發(fā)送多次重復請求 以下方法可以避免這種情況,下面這篇文章主要給大家介紹了關于vue中如何防止用戶頻繁點擊按鈕的相關資料,需要的朋友可以參考下
    2022-09-09
  • Vue加入購物車判斷token添加登錄提示功能

    Vue加入購物車判斷token添加登錄提示功能

    加入購物車,是一個登錄后的用戶 才能進行的操作,所以需要進行鑒權判斷,判斷用戶token是否存在,這篇文章主要介紹了Vue加入購物車判斷token添加登錄提示,需要的朋友可以參考下
    2023-11-11

最新評論

镇巴县| 新建县| 德格县| 平遥县| 昌都县| 汤阴县| 通城县| 中阳县| 绥棱县| 建宁县| 平定县| 河北省| 乐至县| 琼结县| 仙居县| 天全县| 通河县| 丰原市| 克拉玛依市| 龙泉市| 南木林县| 舞钢市| 启东市| 当阳市| 那坡县| 西藏| 新安县| 临澧县| 荣成市| 台北县| 周宁县| 太仓市| 蕉岭县| 兴海县| 翁牛特旗| 临夏县| 贵州省| 沈丘县| 监利县| 黄陵县| 宁津县|