samedi 1 août 2020

how to read another javascript JSON categories

I have no idea how to make this,

I have a loop for product List Item, but i really don't know how to link the shop item to shop name. I have tried many method but i really don't know how to link the item to the shop.
if productList.ShopId = shopList.id then use this shopList.title
SHOP NAME = shopList.title

const getProductList = function (productItem) {
    const productListRender = 
    $('<div>').append($('<span>', {
        html: shopName() <<<< SHOP NAME
    }));

    $.each(data.shopList), function shopName() {
        this.text(shopList.title);
    };
        
    return productListRender;
}
const $product = $('#List')
$.each(data.productList, function (index, data) {
    $product.append(getProductList(data));
});

Data JS is Below:

var data = {
    productList: [
        {
            id: "62276197-6059-4c21-9b40-c5b1d277e85d",
            link: "javascript:void(0)",
            imgurl: "/img/upload/png/joyacart_000001_12032019.png",
            text: 'Product 001',
            goldMedal: false,
            newItem: true,
            newShop: true,
            freeDelivery: true,
            ShopId: '5cfb048c-86e8-4d2d-85bf-e4e9e1effdcb'
        },
        {
            id: "59de8216-052d-4e51-9f7d-7e96642ded62",
            link: "javascript:void(0)",
            imgurl: "/img/upload/png/joyacart_000002_12032019.png",
            text: 'Product 002',
            goldMedal: true,
            newItem: false,
            newShop: true,
            freeDelivery: true,
            ShopId: '10eb4250-47d6-41ad-a429-f65e05836f26'
        },
        {
            id: "59de8216-052d-4e51-9f7d-7e96642ded62",
            link: "javascript:void(0)",
            imgurl: "/img/upload/png/joyacart_000003_12032019.png",
            text: 'Product 003',
            goldMedal: true,
            newItem: false,
            newShop: true,
            freeDelivery: true,
            ShopId: '10eb4250-47d6-41ad-a429-f65e05836f26'
        }],

    shopList: [{
        id: '5cfb048c-86e8-4d2d-85bf-e4e9e1effdcb',
        title: 'Shop 001'
    },
    {
        id: '10eb4250-47d6-41ad-a429-f65e05836f26',
        title: 'Test Shop'
    }]
}



Aucun commentaire:

Enregistrer un commentaire