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

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

請(qǐng)問在JSON對(duì)象上使用jQuery的find()

請(qǐng)問在JSON對(duì)象上使用jQuery的find()

Qyouu 2019-09-03 12:04:11
在JSON對(duì)象上使用jQuery的find()與brnwdrng的問題類似,我正在尋找一種搜索類似JSON的對(duì)象的方法。假設(shè)我的對(duì)象的結(jié)構(gòu)是這樣的:TestObj = {     "Categories": [{         "Products": [{             "id": "a01",             "name": "Pine",             "description": "Short description of pine."         },         {             "id": "a02",             "name": "Birch",             "description": "Short description of birch."         },         {             "id": "a03",             "name": "Poplar",             "description": "Short description of poplar."         }],         "id": "A",         "title": "Cheap",         "description": "Short description of category A."     },     {         "Product": [{             "id": "b01",             "name": "Maple",             "description": "Short description of maple."         },         {             "id": "b02",             "name": "Oak",             "description": "Short description of oak."         },         {             "id": "b03",             "name": "Bamboo",             "description": "Short description of bamboo."         }],         "id": "B",         "title": "Moderate",         "description": "Short description of category B."     }]};我想得到一個(gè)id =“A”的對(duì)象。我嘗試過各種各樣的東西,比如:$(TestObj.find(":id='A'"))但似乎沒什么用。任何人都可以想到一種基于某些標(biāo)準(zhǔn)檢索項(xiàng)目而不使用“每個(gè)”的方法嗎?
查看完整描述

3 回答

?
瀟瀟雨雨

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

這適用于[{“id”:“data”},{“id”:“data”}]

function getObjects(obj, key, val) {
    var newObj = false; 
    $.each(obj, function()
    {
        var testObject = this; 
        $.each(testObject, function(k,v)
        {
            //alert(k);
            if(val == v && k == key)
            {
                newObj = testObject;
            }
        });
    });

    return newObj;}



查看完整回答
反對(duì) 回復(fù) 2019-09-05
  • 3 回答
  • 0 關(guān)注
  • 460 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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