Guest User

Untitled

a guest
Feb 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. // var tree = [
  2. // {
  3. // "children": [
  4. // {
  5. // "id": "BioFine",
  6. // "label": "BioFine"
  7. // },
  8. // {
  9. // "id": "Brewing Salts",
  10. // "label": "Brewing Salts"
  11. // },
  12. // {
  13. // "id": "CO2",
  14. // "label": "CO2"
  15. // },
  16. // {
  17. // "id": "Hops",
  18. // "label": "Hops"
  19. // },
  20. // {
  21. // "id": "Kettle Coagulants",
  22. // "label": "Kettle Coagulants"
  23. // },
  24. // {
  25. // "id": "Malt",
  26. // "label": "Malt"
  27. // },
  28. // {
  29. // "id": "O2",
  30. // "label": "O2"
  31. // },
  32. // {
  33. // "id": "Yeast",
  34. // "label": "Yeast"
  35. // }
  36. // ],
  37. // "id": "Beer",
  38. // "label": "Beer"
  39. // },
  40. // {
  41. // id: 'fruit',
  42. // label: 'Fruit',
  43. // children: [
  44. // { id: 'apple', label: 'Apple' },
  45. // { id: 'banana', label: 'Banana',
  46. // children: [
  47. // { id: 'cherry', label: 'Cherry' }
  48. // ] }
  49. // ]
  50. // }
  51. // ];
  52.  
  53. var flattenList = [];
  54. var flattenObject = function(tree) {
  55. _.forEach(tree, function(value, i) {
  56. if (!_.has(tree, i)) return;
  57. if (_.isObject(tree[i]) && !_.isNull(tree[i])) {
  58. var flatObject = flattenObject(tree[i]);
  59. _.forEach(flatObject, function(v, x) {if (!_.has(flatObject, x)) return;});
  60. } else {
  61. if(i === "label"){
  62. flattenList.push(tree[i]);
  63. }
  64. }
  65. });
  66. return flattenList;
  67. };
Add Comment
Please, Sign In to add comment