Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var data = [
- {
- "node":"h1",
- "text":"Why Loving Others is Good Business",
- "slug":"why-loving-others-is-good-business"
- },
- {
- "node":"h2",
- "text":"Why Loving Others is Good Business",
- "slug":"why-loving-others-is-good-business"
- },
- {
- "node":"h2",
- "text":"Sales Hole",
- "slug":"sales-hole"
- },
- {
- "node":"h3",
- "text":"Booking Shows",
- "slug":"booking-shows"
- },
- {
- "node":"h4",
- "text":"Partner with your Team for a Smart Start",
- "slug":"partner-with-your-team-for-a-smart-start"
- },
- {
- "node":"h3",
- "text":"Serving Clients",
- "slug":"serving-clients"
- },
- {
- "node":"h4",
- "text":"Start Qualifying for the Serving Clients Challenge!",
- "slug":"start-qualifying-for-the-serving-clients-challenge"
- },
- {
- "node":"h5",
- "text":"Start Qualifying for the Serving Clients Challenge!",
- "slug":"start-qualifying-for-the-serving-clients-challenge"
- },
- {
- "node":"h6",
- "text":"Start Qualifying for the Serving Clients Challenge!",
- "slug":"start-qualifying-for-the-serving-clients-challenge"
- },
- {
- "node":"h4",
- "text":"Start Qualifying for the Serving Clients Challenge!",
- "slug":"start-qualifying-for-the-serving-clients-challenge"
- },
- {
- "node":"h2",
- "text":"fdfdfdf",
- "slug":"complete-your-elearning-so-you-can-begin-using-clio-go"
- },
- {
- "node":"h3",
- "text":"Complete Your eLearning So You Can Begin Using CLIO GO!",
- "slug":"complete-your-elearning-so-you-can-begin-using-clio-go"
- },
- {
- "node":"h3",
- "text":"Announcing Our Online Hostess Planner 101 Webinar",
- "slug":"announcing-our-online-hostess-planner-101-webinar"
- },
- {
- "node":"h3",
- "text":"Stylist eCommerce Launches February 1",
- "slug":"stylist-ecommerce-launches-february-1"
- },
- {
- "node":"h2",
- "text":"Team Building",
- "slug":"team-building"
- },
- {
- "node":"h3",
- "text":"Intentional Sharing",
- "slug":"intentional-sharing"
- },
- {
- "node":"h4",
- "text":"Confidently Sharing cabi Builds More Confidence!",
- "slug":"confidently-sharing-cabi-builds-more-confidence"
- },
- {
- "node":"h4",
- "text":"Applications Open Monday!",
- "slug":"applications-open-monday"
- },
- {
- "node":"h3",
- "text":"Your Canada Questions\u00e2\u0080\u00a6Answered",
- "slug":"your-canada-questionsa-answered"
- },
- {
- "node":"h3",
- "text":"Register for our UK Team Building Webinar",
- "slug":"register-for-our-uk-team-building-webinar"
- },
- {
- "node":"h2",
- "text":"To Know",
- "slug":"to-know"
- },
- {
- "node":"h3",
- "text":"Month-at-a-Glance",
- "slug":"month-at-a-glance"
- },
- {
- "node":"h3",
- "text":"Announcing Your Spring 2016 CAM Teams",
- "slug":"announcing-your-spring-2016-cam-teams"
- },
- {
- "node":"h3",
- "text":"New Arrivals Personal Purchase Pre-Orders",
- "slug":"new-arrivals-personal-purchase-pre-orders"
- },
- {
- "node":"h3",
- "text":"Upload Your Photo to Your Personal cabionline Website",
- "slug":"upload-your-photo-to-your-personal-cabionline-website"
- },
- {
- "node":"h3",
- "text":"Just In\u00e2\u0080\u0094Additional Future Scoop Dates & Locations!",
- "slug":"just-ina-additional-future-scoop-dates-locations"
- },
- {
- "node":"h1",
- "text":"Why Loving Others is Good Business",
- "slug":"why-loving-others-is-good-business"
- },
- {
- "node":"h2",
- "text":"To Enjoy",
- "slug":"to-enjoy"
- },
- {
- "node":"h3",
- "text":"Quick Quotables for the Spring 2016 Collection",
- "slug":"quick-quotables-for-the-spring-2016-collection"
- },
- {
- "node":"h3",
- "text":"Blog Preview: How Becky Styled Spring",
- "slug":"blog-preview-how-becky-styled-spring"
- }
- ];
- function treeChild(data) {
- var tree ={
- children: []
- };
- tree.children.push({
- level: nEl(data[0].node),
- element: data[0],
- children: [],
- parent: tree
- });
- var lastElement = tree.children[0];
- for (var i = 1; i<data.length; i++){
- var actualElement = data[i];
- if(lastElement.level < nEl(actualElement.node)){
- var child = {
- level: lastElement.level+1,
- element: data[i],
- children: [],
- parent: lastElement
- };
- lastElement.children.push(child);
- lastElement = child;
- }else if(lastElement.level > nEl(actualElement.node)){
- var diference = (lastElement.level - nEl(actualElement.node));
- var parent = lastElement.parent;
- var newlevel= lastElement.level;
- for(var x=0; x<diference; x++){
- newlevel--;
- parent = parent.parent;
- }
- var child = {
- level: newlevel,
- element: data[i],
- children: [],
- parent: parent
- };
- parent.children.push(child);
- lastElement = child;
- }else {
- var child = {
- level: lastElement.level,
- element: data[i],
- children: [],
- parent: lastElement.parent
- };
- lastElement.parent.children.push(child);
- lastElement = child;
- }
- }
- return tree;
- }
- function nEl(text) {
- return parseInt(text.slice(1,2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement