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"
}
}
};
上面當我選取:
颜色的data-aid为3,规格的data-aid为13时,默认价格更新为3_13对应的价格
data-aid为3, 规格的data-aid为14时,默认价格更新为3_14对应的价格
data-aid为4, 规格的data-aid为13时,默认更新为4_13对应的价格
第二種:
{
"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"
}
]
}
預設
颜色product_color: 625
规格product_spec: 627
价格为46.15
当选择product_color: 625, 规格为628,对应价格为50.00
当选择product_color: 629, 规格为627,对应的价格为33.00
這兩種json資料格式那種更為簡潔,效率更有效率?
有資料冗餘重複的時候,盡量消除資料的重複。上面的兩種資料組織方式都沒有冗餘,但是為了查詢方便,資料格式的組織可以像資料庫一樣,有一個方便查詢的主鍵,也可以說是id。所以個人覺得上面的那種方式好一點,可以直接用key查到value。而下面的那種方式感覺查詢起來有些麻煩。
資料格式的組織也盡量範式化:
上面的引述是來自Redux官方文件推薦的state組織方式,可以參考一下。