Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. [
  2. {
  3. "N": "3M",
  4. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  5. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  6. "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  7. "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
  8.  
  9. },
  10.  
  11. {
  12. "N": "ABC corp",
  13. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  14. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  15. "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>",
  16. "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
  17.  
  18. }
  19. ]
  20.  
  21. [
  22. {
  23. "N": "3M",
  24. "a": "red",
  25. "c": "red",
  26. "r": "red",
  27. "p": "gray"
  28.  
  29. },
  30.  
  31. {
  32. "N": "ABC corp",
  33. "a": "red",
  34. "c": "red",
  35. "r": "green",
  36. "p": "gray"
  37.  
  38. }
  39. ]
  40.  
  41. var data = [{
  42. "N": "3M",
  43. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  44. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  45. "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  46. "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
  47.  
  48. }, {
  49. "N": "ABC corp",
  50. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  51. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  52. "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>",
  53. "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
  54.  
  55. }];
  56.  
  57. var modified = data.reduce(function (outArr, entry) {
  58. var outObj = {};
  59. for (key in entry) {
  60. if (entry.hasOwnProperty(key)) {
  61. var item = entry[key];
  62. var node = document.createElement("div");
  63. node.innerHTML = item;
  64. var img = node.querySelector("img");
  65. outObj[key] = img ? img.alt : item;
  66. }
  67. }
  68. outArr.push(outObj);
  69. return outArr;
  70. }, []); //[{"N":"3M","a":"red","c":"red","r":"red","p":" "},{"N":"ABC corp","a":"red","c":"red","r":"green","p":" "}]
  71.  
  72. var obj=[
  73. {
  74. "N": "3M",
  75. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  76. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  77. "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>"
  78. },
  79. {
  80. "N": "ABC corp",
  81. "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  82. "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
  83. "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>"
  84. }
  85. ];
  86.  
  87. for(var k in obj){
  88. for (name in obj[k]) {
  89. if(obj[k][name].indexOf("<img") != -1) {
  90. // I have made logic based on "flag_", this can be change as per your requirement.
  91. var src= obj[k][name].substring(obj[k][name].indexOf("flag_")+5,obj[k][name].indexOf(".gif"));
  92. obj[k][name]=src;
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement