三种数据结构
一、第一种数据结构
activities = [ { name: "first activity", sign_ups: [], bids: [] }, { name: "first activity", sign_ups: [ { name: "仝键", phone: "13600000000" }, { name: "于硕", phone: "15600000000" } ], bids: [ { name: "竞价1", biddings: [ { name: "仝键", phone: "13600000000", price: "12" }, { name: "于硕", phone: "15600000000", price: "10" } ] } ] } ];
这种数据存储结构是把所有的信息都存在一个数组里,包括活动名称、活动信息、竞价名称、竞价信息,会显得这个数组非常拥挤,虽然调用方面会比较容易,结构上也很清晰,但是弊端也很明显,就是来回的嵌套,修改某一项具体数据时会显得很麻烦,利弊对半开吧。。。
二、第二种数据结构
activities = { "0": { name: "first activity", sign_ups: [], bids: [], biddings: {} }, "1": { name: "second activity", sign_ups: [ { name: "仝键", phone: "13600000000" }, { name: "于硕", phone: "15600000000" } ], bids: ["竞价1", "竞价2"], biddings: { "竞价1": [ { phone: "13600000000", price: "12" }, { phone: "15600000000", price: "10" } ], "竞价2": [ { phone: "13600000000", price: "10" }, { phone: "15600000000", price: "12" }, ] } ] };
这种数据存储结构用到了哈希的存储方式,将数据结构的所有信息都存在一个哈希表中,每个活动对应一个键,这个键所对应的value有包括了其他报名和竞价的各种信息,较之第一种结构,就相当于把竞价的名称有单独拿出来做了一个数组,每个竞价名都对应一个存储他信息的信息数组,这样取的时候直接通过键值对的关系,就可以存取和修改数据了。
三、第三种数据结构
activities = [ { id: "0", name: "first activity" }, { id: "1", name: "second activity" } ]; sign_ups = [ { name: "仝键", phone: "13600000000", activity_id: "0" }, { name: "于硕", phone: "15600000000", activity_id: "0" } ] bids = [ { name: "竞价1", activity_name: "0", biddings: [ { phone: "13600000000", price: "9" }, { phone: "15600000000", price: "10" } ] } ];
这种数据结构是将所有不同类别的信息都存成了一个单一的数组,在数据联系上并没有前两种方式清晰,但是相对而言,没有之前那么多的嵌套结构,数组内容更简单,修改和存取数据的时候会显得很轻松快捷。
相关推荐
LauraRan 2020-09-28
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31