javascript - In mall development, which json data format do you tend to use for attribute specifications in product details pages? As follows
大家讲道理
大家讲道理 2017-07-05 10:47:55
0
1
706
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"
                    }
                }
            };

When I selected the above:

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

Second type:

{
    "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"
        }
    ]
}

default

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

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

Which of these two json data formats is more concise and efficient?

大家讲道理
大家讲道理

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

reply all(1)
phpcn_u1582

When there is redundant duplication of data, try to eliminate the duplication of data. There is no redundancy in the above two data organization methods, but for the convenience of query, the data format can be organized like a database, with a primary key for easy query, which can also be said to be id. So I personally feel that the above method is better, as you can directly check the value through the key. The following method seems a bit troublesome to query.

The organization of the data format is also as standardized as possible:

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

The above quote is from the state organization method recommended by Redux official documentation, you can refer to it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!