依赖选项列表的结构

时间:2014-01-15 18:37:27

标签: javascript data-structures

我有3个依赖选项列表,因此类别选项列表值取决于组值,而SubCategory值取决于类别。在Javascript中定义描述这些依赖关系的结构有什么好方法?为什么?我有三个变种。

//1
var myStruct =   {
            "Group1" : {
                "category1": ["subcategory1","subcategory2"],
                "category2": ["subcategory1","subcategory2"],
                "category3" :["subcategory1","subcategory2"]
                },
    "Group2" :{
                "category1": ["subcategory1","subcategory2"],
                "category2": ["subcategory1","subcategory2"],
                "category3" :["subcategory1","subcategory2"]
               }            
            };

//2
var myStruct2 =   {
    "Group1" : {
                "category1": {
                    "subcategory1":null,
                    "subcategory2":null
                },
                 "category2": {
                     "subcategory3":null,
                    "subcategory4":null
                },
                "category3": {
                     "subcategory5":null,
                    "subcategory6":null
                }
    },
           "Group2" :
                {
                "category3": {
                    "subcategory7":null,
                    "subcategory8":null
                },
                "category4": {
                     "subcategory9":null,
                    "subcategory10":null
                },
                "category5": {
                     "subcategory11":null,
                    "subcategory12":null
                }             
            }
        }


//3  - two separate objects describing  each  dependency

var dependency1 = {
  "Group1" :["category1","category2","category3"],
  "Group2" :["category4","category5","category6"]
  }

 var dependency2 = {
  "category1": ["subcategory1","subcategory2"],
  "category1": ["subcategory3","subcategory4"],
  "category1": ["subcategory5","subcategory6"],
  "category1": ["subcategory7","subcategory8"],
  "category1": ["subcategory9","subcategory10"],
  "category1": ["subcategory11","subcategory12"]

 }

或此任务的任何替代说明?

0 个答案:

没有答案