javascript - Traverse an object tree and render a menu tree based on object property condition -


hello i'm trying create html menu given object following , wondering if there library can me traverse object, instead of reinventing wheel.

var root = {     category1: {         depth: 0,         categories: {             category1: {                 depth: 1              },             category2: {                 depth: 1,                 products: [1, 2, 3, 4, 5]              },             category3: {                 depth: 1,                 categories: {                     category1: {                         depth: 2,                         products: [1, 2, 3, 4]                     },                     category2: {                         depth: 2,                         products: [1, 2, 3, 4, 5, 6, 7]                     },                     category3: {                         depth: 2                      }                  }             }         }     },     category2: {         depth: 0,         category1: {             depth: 1,         },         category2: {             depth: 1,             products:[1,2,3,4,5]          }     },     category3: {         depth: 0,         category1: {             depth: 1,          },         category2: {             depth: 1,             categories: {                 category1: {                     depth: 2,                     products: [1, 2, 3, 4]                 },                 category2: {                     depth: 2,                     products: [1, 2, 3, 4, 5, 6, 7]                 },                 category3: {                     depth: 2                  }              }          }     },     depth: 0,     category4: {         category1: {             depth: 1,             products:[1,2,3,4,5]         },         category2: {             depth: 1,             categories: {                 category1: {                     depth: 2,                     products: [1, 2, 3, 4]                 },                 category2: {                     depth: 2,                     products: [1, 2]                 },                 category3: {                     depth: 2                  }              }          },         category3: {             depth: 1,          }     }  }; 

i'm interested in creating menu paths - nodes leaf categories have products other must discarded , not rendered. products can found in level 1 , 2 categories. , each category has depth indicator property indicating level of category.

for example if root category has no leaf level category products not rendered, or depth 1 category no leafs products must not rendered.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -