search

Home  >  Q&A  >  body text

javascript - In mall development, which json data format do you tend to use for attribute specifications in product details pages? As follows

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?

大家讲道理大家讲道理2728 days ago749

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-07-05 10:49:55

    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.

    reply
    0
  • Cancelreply