javascript - Type of datastructure -


i have multiple questions contains sub questions. store in data structure can choose sub question when user selects first question. also, sub questions uses general questions within category. thought using multidimensional array realized take quite long time search through array.

any suggestion appreciated.

thank you

this solution far.

//key question , value(object) contains value related 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 countertop project?":{                                 "install_or_replace": "install or replace",                                 "repair"        : "repair",                                 "selectkey":"describe_countertop_project"                             },                              "generalquestions2": "4"                             }; //this general question other categories might use...it being used in above category generalquestion[4] = {"is project part of larger remodel?":{                             "true" : "yes",                             "false": "no",                             "selectkey":"part_of_larger_remodel"                         }                     }; //this categorytosuquestion index value assosciation...(just keep track) var keyvalue = new array( /*0*/           "cabinets_reface", /*1*/           "cabinets_refinish", /*2*/           "cabinets_countertop_install"); 

i have 70 of right , little worried if slow down once keep adding more questions?

i'd create data structure this.
don't forget can access hashtable/dictionary on properties.

var questions_data_structure = {     "q1": {         "question_text": "parent question #1?",         "sub_questions": ["subques1", "subques3"]     },     "subques1": {         "question_text": "sub question 1?",         "parent_question": "q1"     },     "subques3": {         "question_text": "sub question 3?",         "parent_question": "q1"     },     "ques8": {         "question_text": "regular question without children questions?"     } }  q = questions_data_structure["q1"]; alert(q.question_text);  if (q.sub_questions && q.sub_questions.length > 0) {     alert("i have child questions");      var = 0, len = q.sub_questions.length, childquestionobj;     (; < len; i++) {         childquestionobj = questions_data_structure[q.sub_questions[i]];         alert(childquestionobj.question_text);     } } else {     alert("i don't have child questions"); } 

so if tie data structure's key values html control ids, can this.

// include jquery library $.each(questions_data_structure, function(question_id, value) {     if (value.sub_questions && value.sub_questions.length > 0) {         $('#' + question_id).click( function(e) {             /* show or hide child question controls */         });     } }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -