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

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

js遍歷json根據(jù)id選擇屬性值顯示對應(yīng)的div?

js遍歷json根據(jù)id選擇屬性值顯示對應(yīng)的div?

猛跑小豬 2019-04-27 19:15:35
有3個json,它們之間可以找到相同的id,我想要的是選擇了屬性1下面的屬性值,然后再選擇屬性2下面的屬性值(屬性1是必有的,但是屬性2可能有的情況下沒有),請問我該怎么寫js可以實(shí)現(xiàn)?//屬性1var arr1 = {"attributes": {"1": {"id": "1","options": [{"id": "2","products": ["4", "5"]}, {"id": "3","label": "0.05Ohm","price": "3","oldPrice": "3","products": ["6"]}]},"7": {"id": "7","options": [{"id": "8","products": ["4"]}, {"id": "9","products": ["10"]}]}},"template": "price",}//屬性2var arr2 = {"7":{"8":["4"],"9":["10"]},"1":{"2":["4","5"],"3":["6"]}}//倉庫var arr3={"4":{"qty":"5","html":"Warehouse1”},"5":{"qty":"6","html":"Warehouse2"},"6":{"qty":"22","html":"Warehouse3"},"10":{"qty":"13","html":"Warehouse4"}}
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個贊

建議使用markdown語法格式化一下JS代碼,提高適讀性,如:

var arr1 = {
    "attributes": {
        "1": {
            "id": "1",
            "options": [{
                    "id": "2",
                    "products": ["4", "5"]
                }, {
                    "id": "3",
                    "label": "0.05Ohm",
                    "price": "3",
                    "oldPrice": "3",
                    "products": ["6"]
                }
            ]
        },
        "7": {
            "id": "7",
            "options": [{
                    "id": "8",
                    "products": ["4"]
                }, {
                    "id": "9",
                    "products": ["10"]
                }
            ]
        }
    },
    "template": "price",
}
//屬性2
var arr2 = {
    "7": {
        "8": [
            "4"
        ],
        "9": [
            "10"
        ]
    },
    "1": {
        "2": [
            "4",
            "5"
        ],
        "3": [
            "6"
        ]
    }
}
//倉庫
var arr3 = {
    "4": {
        "qty": "5",
        "html": "

        Warehouse1
        "
    },
    "5": {
        "qty": "6",
        "html": "
        Warehouse2
        "
    },
    "6": {
        "qty": "22",
        "html": "
        Warehouse3
        "
    },
    "10": {
        "qty": "13",
        "html": "
        Warehouse4
        "
    }
}
<dl>
    <dt>
        <label>屬性1</label>
    </dt>
    <dd>
        <select name="super_attribute[1]" id="attribute1">
            <option value="">Choose an Option...</option>
            <option value="2">0.04Ohm</option>
            <option value="3">0.05Ohm</option>
        </select>
    </dd>
    <dt>
        <label>屬性2</label>
    </dt>
    <dd>
        <select name="super_attribute[7]" id="attribute7">
            <option value="">Choose an Option...</option>
            <option value="8">Black</option>
            <option value="9">Red</option>
        </select>
    </dd>
    <dt>
        <label>Warehouse</label>
    </dt>
    <dd>
        <!--根據(jù)上面選擇的屬性值顯示對應(yīng)的倉庫內(nèi)容-->
    </dd>
</dl>
<dl>
    <dt>
        <label>屬性1</label>
    </dt>
    <dd>
        <select name="super_attribute[1]" id="attribute1">
            <option value="">Choose an Option...</option>
            <option value="2">0.04Ohm</option>
            <option value="3">0.05Ohm</option>
        </select>
    </dd>
    <dt>
        <label>屬性2</label>
    </dt>
    <dd>
        <select name="super_attribute[7]" id="attribute7">
            <option value="">Choose an Option...</option>
            <option value="8">Black</option>
            <option value="9">Red</option>
        </select>
    </dd>
    <dt>
        <label>Warehouse</label>
    </dt>
    <dd>
        <!--根據(jù)上面選擇的屬性值顯示對應(yīng)的倉庫內(nèi)容-->
    </dd>
</dl>


查看完整回答
反對 回復(fù) 2019-05-08
?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個贊

知識考察點(diǎn):遍歷對象,遍歷數(shù)組的用法

案例:
var A = {a:1,b:2,c:3,d:"hello world"};

for(var k in A) {

console.log(k,A[k]);


輸出內(nèi)容:
a 1
b 2
c 3
d hello world


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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