Friday, October 4, 2024
HomeGolangEasy methods to created nested struct - Getting Assist

Easy methods to created nested struct – Getting Assist


Hello ,

I've following desk .
myid	parentid	menu_name
1	0	Video Gamers
2	0	Televisions
11	1	HD Video Participant
12	1	CD participant
13	1	USB participant
21	2	SuperLCD 42
22	2	SuperLED 42
23	2	SuperLED 50
24	2	SuperLCD 55 (Not accessible)
25	2	SuperLCD 70
111	11	Video1
112	11	Video2
1111	111	Video111
1112	111	Video112

I need this sort of json object 

[{
  id: '1',
  name: 'Video Players',
  items: [{
    id: '1_1',
    name: 'HD Video Player',
    price: 220,
    icon: 'images/products/1.png',
  }, {
    id: '1_2',
    name: 'SuperHD Video Player',
    icon: 'images/products/2.png',
    price: 270,
  }],
}, {
  id: '2',
  title: 'Televisions',
  gadgets: [{
    id: '2_1',
    name: 'SuperLCD 42',
    icon: 'images/products/7.png',
    price: 1200,
  }, {
    id: '2_2',
    name: 'SuperLED 42',
    icon: 'images/products/5.png',
    price: 1450,
  }, {
    id: '2_3',
    name: 'SuperLED 50',
    icon: 'images/products/4.png',
    price: 1600,
  }, {
    id: '2_4',
    name: 'SuperLCD 55 (Not available)',
    icon: 'images/products/6.png',
    price: 1350,
    disabled: true,
  }, {
    id: '2_5',
    name: 'SuperLCD 70',
    icon: 'images/products/9.png',
    price: 4000,
  }],
}, {
  id: '3',
  title: 'Displays',
  gadgets: [{
    id: '3_1',
    name: '19"',
    items: [{
      id: '3_1_1',
      name: 'DesktopLCD 19',
      icon: 'images/products/10.png',
      price: 160,
    }],
  }, {
    id: '3_2',
    title: '21"',
    gadgets: [{
      id: '3_2_1',
      name: 'DesktopLCD 21',
      icon: 'images/products/12.png',
      price: 170,
    }, {
      id: '3_2_2',
      name: 'DesktopLED 21',
      icon: 'images/products/13.png',
      price: 175,
    }],
  }],
}, {
  id: '4',
  title: 'Projectors',
  gadgets: [{
    id: '4_1',
    name: 'Projector Plus',
    icon: 'images/products/14.png',
    price: 550,
  }, {
    id: '4_2',
    name: 'Projector PlusHD',
    icon: 'images/products/15.png',
    price: 750,
  }],
}]

I’ve tried all choice . I can’t capable of created at runtime array with fields

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments