第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

搜索并替換標(biāo)題鍵嵌套對象vue js上的字符串

搜索并替換標(biāo)題鍵嵌套對象vue js上的字符串

長風(fēng)秋雁 2023-09-21 16:51:56
我有一個(gè)嵌套對象,其中包含幾個(gè)鍵,這些鍵還包括標(biāo)題和子項(xiàng)。Children 是也具有標(biāo)題和子鍵的對象數(shù)組。(它們看起來像一棵樹)如何搜索和替換標(biāo)題值的一個(gè)單詞或一部分?const object = {    id: 'uuid',    title: 'hello You',    type: number,    visibility: true,    children: [        {            id: 'uuid',            title: 'You don't have any comments...',            type: number,            visibility: true,            children: [{...}, {...}, ...],            key1: {...},            key2: [{...}]        },        {            id: 'uuid',            title: 'You your problem is not with json...',            type: number,            visibility: true,            children: [{...}, {...}, ...],            key1: {...},            key2: [{...}]       }    ],    key1: {...},    key2: [{...}]}搜索you并替換world標(biāo)題output = {    id: 'uuid',    title: 'hello world',    type: number,    visibility: true,    children: [        {            id: 'uuid',            title: 'world don't have any comments...',            type: number,            visibility: true,            children: [{...}, {...}, ...],            key1: {...},            key2: [{...}]        },        {            id: 'uuid',            title: 'world your problem is not with json...',            type: number,            visibility: true,            children: [{...}, {...}, ...],            key1: {...},            key2: [{...}]       }    ],    key1: {...},    key2: [{...}]}
查看完整描述

1 回答

?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以嘗試使用遞歸策略來查找數(shù)組中的任何鍵,并搜索它們的子項(xiàng)。


function recursive (newArray) {

  newArray.map(obj => {

    if (obj.title) {

      obj.title = obj.title.replace(/You/g, 'world')

    }

    if (obj.children) {

      return recursive (obj.children)

    }

  })

  return newArray

}

使用該功能


let arr = [object]


recursive(arr)


查看完整回答
反對 回復(fù) 2023-09-21
  • 1 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號