Untitled


SUBMITTED BY: Guest

DATE: June 15, 2013, 4:34 p.m.

FORMAT: Text only

SIZE: 2.5 kB

HITS: 31293

  1. [{
  2. "guide": null,
  3. "residence": [{
  4. "name_r": "jack"
  5. }, {
  6. "name_r": "jim"
  7. }, {
  8. "name_r": "sara"
  9. }],
  10. "residence_u": [{
  11. "units": ["hello", "how", "what"],
  12. "extra": ["11", "22", "33"],
  13. "price": ["1,111,111", "2,222,222", "3,333,333"]
  14. }, {
  15. "units": ["fine"],
  16. "extra": ["44"],
  17. "price": ["4,444,444"]
  18. }, {
  19. "units": ["thanks", "good"],
  20. "extra": ["55", "66"],
  21. "price": ["5,555,555", "6,666,666"]
  22. }]
  23. }]
  24. success: function (data) {
  25. $.each(data[0].residence, function (index, value) {
  26. $('ol#residence_name').append('<li><a href="" class="tool_tip" title="ok">' + value.name_r + '</a><div class="tooltip"></div></li>');
  27. var info = data[0].residence_u[index];
  28. $.each(info.units, function (index, value) {
  29. $('ol#residence_name li .tooltip').append(value + ' & ' + info.extra[index] + ' & ' + info.price[index] + '<br>');
  30. })
  31. });
  32. var $li = $('<li><a href="" class="tool_tip" title="ok">' + value.name_r + '</a></li>');
  33. var $tooltip = $('<div class="tooltip"></div>').appendTo($li);
  34. var info = data[0].residence_u[index];
  35. $.each(info.units, function (index, value) {
  36. $tooltip.append(value + ' & ' + info.extra[index] + ' & ' + info.price[index] + '<br>');
  37. });
  38. $li.appendTo('#residence_name');
  39. // Declare the variables we're going to use
  40. var i, j; // Iterating variables
  41. var name, unitsArray, extraArray, priceArray; // Outer loop
  42. var unit, extra, price; // Inner loop
  43. // Loop through the people
  44. for( i in data[0].residence ) {
  45. // Assign the outer-loop variables
  46. name = data[0].residence[i].name_r;
  47. unitsArray = data[0].residence_u[i].units;
  48. extraArray = data[0].residence_u[i].extra;
  49. priceArray = data[0].residence_u[i].price;
  50. // Do something here with the name
  51. // For each person, loop through the things they said
  52. for( j in unitsArray ) {
  53. // Assign the inner-loop variables
  54. unit = unitsArray[j];
  55. extra = extraArray[j];
  56. price = priceArray[j];
  57. // Do something here with the 3 inner-loop variables
  58. }
  59. }

comments powered by Disqus