Advertisement
arijulianto

jSON kebalik

Aug 25th, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.83 KB | None | 0 0
  1. JSON
  2. res = {
  3.     "count": 5,
  4.     "head": ["kode", "jenis"],
  5.     "data": [{
  6.         "001": "001",
  7.         "1": "Dispenser"
  8.     }, {
  9.         "004": "004",
  10.         "4": "DVD Player"
  11.     }, {
  12.         "005": "005",
  13.         "5": "Kipas Angin"
  14.     }, {
  15.         "002": "002",
  16.         "2": "Radio Tape"
  17.     }, {
  18.         "003": "003",
  19.         "3": "Televisi"
  20.     }]
  21. }
  22.  
  23.  
  24.  
  25. jQuery
  26. items += '<tr>';
  27. $.each(res.head, function(kh, vh){
  28.     items += '<th>'+vh+'</th>';
  29. });
  30.        
  31. items += '</tr>';
  32. $.each(res.data, function(key,vals){
  33.      items += '<tr>';
  34.      $.each(vals, function(k, v){
  35.         items += '<td data-value="'+k+'">'+v+'</td>';
  36.      });
  37.      items += '</tr>';
  38. });
  39.        
  40. $(target).append(win);
  41. $('.searchContent').html('<table class="table table-bordered table-striped">'+items+'</table>').find('tbody tr:first').addClass('selected');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement