我有多個問題,其中包含子問題。我想存儲一個數據結構,這樣當用戶選擇第一個問題時,我可以選擇子問題。此外,一些子問題使用該類別中的一般問題。最初我想過使用多維數組,但後來我意識到需要相當長的時間來搜索數組。數據結構的類型
任何建議表示讚賞。
謝謝
這是我迄今爲止的解決方案。
//Key is the question and value(object) contains all the value related to the question
categoryToSubquestions[2] = {"What type of countertop?":{
"stone_slab_countertops": "Stone slab countertops",
"granite_countertops" : "Granite countertops",
"marble_countertops" : "Marble countertops",
"quartz_countertops" : "Quartz countertops",
"slate_countertops" : "Slate countertops",
"solid_surface_countertops" : "Solid Surface countertops",
"concrete_countertops" : "Concrete countertops",
"corian_countertops" : "Corian countertops",
"formica_countertops" : "Formica countertops",
"stainless_countertops" : "Stainless countertops",
"wood_or_butcher_block_countertops" : "Wood or Butcher block countertops",
"laminate_countertops" : "Laminate countertops",
"selectKey":"MappedCategory"
},
"What best describes your countertop project?":{
"install_or_replace": "Install or Replace",
"repair" : "Repair",
"selectKey":"describe_countertop_project"
},
"generalQuestions2": "4"
};
//This is general question that other categories might use...It is being used in the above category
generalQuestion[4] = {"Is this project part of a larger remodel?":{
"true" : "Yes",
"false": "No",
"selectKey":"part_of_larger_remodel"
}
};
//THIS IS categoryToSuquestion index to value assosciation...(JUST TO KEEP TRACK)
var keyValue = new Array(
/*0*/ "cabinets_reface",
/*1*/ "cabinets_refinish",
/*2*/ "cabinets_countertop_install");
我現在有70個這個權利,我有點擔心,如果它會減慢,一旦我不斷增加更多的問題?
聽起來像一棵樹給我。 – ChaosPandion
它可能有助於提供您的數據結構的示例。我不確定你的意思是「一些小問題在這個範疇內使用一般問題」。 – showdev
這一切都發生在客戶端(JavaScript)或者你是否在服務器端從數據庫中進行任何操作? –