Loading ...
Sorry, an error occurred while loading the content.
 

Difficulties with json data

Expand Messages
  • Rahat Bashir
    Dear Experts, I am facing some difficulties with some json type data. Below is the details of problem: data: { error :false, dataset :[ { id : 9 , name : Md.
    Message 1 of 2 , Apr 10, 2012
      Dear Experts, I am facing some difficulties with some json type data. Below is the details of problem:

      data: {"error":false,
               "dataset":[
                               {"id":"9",
                                "name":"Md. Harun Ali Mia",
                                "phone":"0192836465",
                                "interviewer":"Abu Al-Imran"
                               },          
                               {"id":"10",
                                "name":"Mia Bhai",
                                "phone":"0192836465",
                                "interviewer":"Abu Al-Imran"
                               }
                             ]
              }

      I need to print these data into a table. What I did is:

      var $table = $('<table>');
      $.each(data.dataset, function(key, val){
              $table.append($('<tr>').attr({align:'left',valign:'middle'}));
              $.each(val, function(k, v){
                  $table.append($('<td>').text(v));
              });
             
          });

      The problem is this is showing just nothing. If someone could help me a way out.

      Thanks,
      Rahat Bashir


    • shiplu
      ... It can be done with very simple JS. why bother call jQuery too many times? var tbl = for(var i=0;i
      Message 2 of 2 , Apr 10, 2012
        On Tue, Apr 10, 2012 at 6:41 PM, Rahat Bashir <rahat.bashir@...> wrote:


        Dear Experts, I am facing some difficulties with some json type data. Below is the details of problem:

        data: {"error":false,
                 "dataset":[
                                 {"id":"9",
                                  "name":"Md. Harun Ali Mia",
                                  "phone":"0192836465",
                                  "interviewer":"Abu Al-Imran"
                                 },          
                                 {"id":"10",
                                  "name":"Mia Bhai",
                                  "phone":"0192836465",
                                  "interviewer":"Abu Al-Imran"
                                 }
                               ]
                }

        I need to print these data into a table. What I did is:

        var $table = $('<table>');
        $.each(data.dataset, function(key, val){
                $table.append($('<tr>').attr({align:'left',valign:'middle'}));
                $.each(val, function(k, v){
                    $table.append($('<td>').text(v));
                });
               
            });

        The problem is this is showing just nothing. If someone could help me a way out.

        Thanks,
        Rahat Bashir



        It can be done with very simple JS.  why bother call jQuery too many times?

        var tbl = ""
        for(var i=0;i<data.dataset.length;i++){
               var tr = '<tr align="left" valign="middle">';
               var el = data.dataset[i];
               for(j in el){
                   if(el.hasOwnProperty(j)){
                       tr += "<td>" + el[j] + "</td>";
                   }
               } 
               tbl += tr+"</tr>\n";
        }
        $table.append(tbl);
         
        --
        Shiplu.Mokadd.im
        ImgSign.com | A dynamic signature machine

        Innovation distinguishes between follower and leader

      Your message has been successfully submitted and would be delivered to recipients shortly.