-1

I have a requirement where it is necessary to have 2 levels of nesting in an object with state and type something like below

templates = {
   type1: {
              state1: [];
          }
   type2: {
              state2: [];
          }
};

However in one of the cases, I wont be having type but I need to select just based on state in this case. How to achieve this?

Sunil
  • 856
  • 12
  • 24
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Teemu Sep 09 '16 at 07:52
  • You may take a look at HTML5 Web SQL – Denis Sheremet Sep 09 '16 at 08:16
  • Your code is syntactically invalid, due to the semi-colons. You say *I need to select*--select what? –  Sep 09 '16 at 09:51

1 Answers1

0

You could always add another item to your object wich defines the way it should be accessed.

template = {
    // and then either

    accessType : "type",
    type1: {
        state1: [];    
    },
    type2:{
        state2: [];
    }

    // or
    accessType : "state",
    state1: {

    },
    state2: {
    }
}

Based on the accessType you can decide how you want to access the object.

cpalinckx
  • 369
  • 2
  • 5