我有多个问题,其中包含子问题。我想存储一个数据结构,这样当用户选择第一个问题时,我可以选择子问题。此外,一些子问题使用该类别中的一般问题。最初我想过使用多维数组,但后来我意识到需要相当长的时间来搜索数组。数据结构的类型
任何建议表示赞赏。
谢谢
这是我迄今为止的解决方案。
//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)或者你是否在服务器端从数据库中进行任何操作? –