javascript - Dalam pembangunan pusat membeli-belah, format data json yang manakah anda cenderung gunakan untuk spesifikasi atribut dalam halaman butiran produk Seperti berikut
大家讲道理
大家讲道理 2017-07-05 10:47:55
0
1
707
var sys_item = {
                
                "mktprice": "13.00",
                
                "price": "6.80",
                
                "sys_attrprice": {
                    "3_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "3_14": {
                        "price": "7.80",
                        "mktprice": "14.00"
                    },
                    "3_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "3_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    },
                    "4_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "4_14": {
                        "price": "7.80",
                        "mktprice": "14.00"
                    },
                    "4_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "4_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    },
                    "8_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "8_14": {
                        "price": "7.80",
                        "mktprice": "1400"
                    },
                    "8_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "8_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    },
                    "9_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "9_14": {
                        "price": "7.80",
                        "mktprice": "14.00"
                    },
                    "9_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "9_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    },
                    "10_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "10_14": {
                        "price": "7.80",
                        "mktprice": "14.00"
                    },
                    "10_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "10_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    },
                    "12_13": {
                        "price": "6.80",
                        "mktprice": "13.00"
                    },
                    "12_14": {
                        "price": "7.80",
                        "mktprice": "14.00"
                    },
                    "12_16": {
                        "price": "8.80",
                        "mktprice": "15.00"
                    },
                    "12_17": {
                        "price": "9.80",
                        "mktprice": "16.00"
                    }
                }
            };

Apabila saya memilih perkara di atas:

颜色的data-aid为3,规格的data-aid为13时,默认价格更新为3_13对应的价格
    data-aid为3, 规格的data-aid为14时,默认价格更新为3_14对应的价格
    data-aid为4, 规格的data-aid为13时,默认更新为4_13对应的价格

Jenis kedua:

{
    "library":[
        {
            "product_color":"625",
            "product_spec":"626",
            "buyer":"46.15",
            "attribute":"0"
        },
        {
            "product_color":"625",
            "product_spec":"627",
            "buyer":"46.15",
            "attribute":"0"
        },
        {
            "product_color":"625",
            "product_spec":"628",
            "buyer":"50.00",
            "attribute":"1"
        },{
            "product_color":"629",
            "product_spec":"627",
            "buyer":"33.00",
            "attribute":"0"
        }
    ]
}

Lalai

颜色product_color: 625
规格product_spec: 627
价格为46.15

当选择product_color: 625, 规格为628,对应价格为50.00
当选择product_color: 629, 规格为627,对应的价格为33.00

Manakah antara dua format data json ini yang lebih ringkas dan cekap?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

membalas semua(1)
phpcn_u1582

Apabila terdapat pertindihan data yang berlebihan, cuba hapuskan pertindihan data. Tiada redundansi dalam dua kaedah organisasi data di atas, tetapi untuk kemudahan pertanyaan, format data boleh diatur seperti pangkalan data, dengan kunci utama untuk pertanyaan mudah, yang juga boleh dikatakan sebagai id. Jadi saya secara peribadi merasakan bahawa kaedah di atas adalah lebih baik, kerana anda boleh menyemak secara langsung nilai melalui kunci. Kaedah berikut kelihatan agak menyusahkan untuk ditanya.

Penyusunan format data juga diseragamkan yang mungkin:

任何类型的数据在 state 中都有自己的 “表”。
任何 “数据表” 应将各个项目存储在对象中,其中每个项目的 ID 作为 key,项目本身作为 value。
任何对单个项目的引用都应该根据存储项目的 ID 来完成。
ID 数组应该用于排序。

Petikan di atas adalah daripada kaedah organisasi negeri yang disyorkan oleh dokumentasi rasmi Redux, anda boleh merujuknya.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!