简体   繁体   中英

How to get JSON result in grid/tabular format while calling an API?

I'm using railway API in my website and want the Train data in grid format. Please help me with the same.

I want all the variables (Train name, Train number, Departure Time, Arrival Time, Travel Time, Availability Status) in a table format. I'm calling two APIs to get the final result. How can I achieve this using AngularJs?

  function between(trainData) {
    var total = trainData.TotalTrains;

    for (i = 0; i < total; i++) {
      var source = trainData.Trains[i].Source;
      var destination = trainData.Trains[i].Destination;
      var name = trainData.Trains[i].TrainName;
      var number = trainData.Trains[i].TrainNo;
      var ttime = trainData.Trains[i].TravelTime;
      var deptime = trainData.Trains[i].DepartureTime;
      var arrtime = trainData.Trains[i].ArrivalTime;


          $('.' + className + '').append("<br/>" + name + "(" + number + ")" + "  " + ttime + " " + deptime + " " + arrtime  + "<br/>");
        }
      }
    }

你可以跟最后一样追加

$('.' + className + '').append("<table><tr><th>name</th><th>number </th><th>ttime </th><th>deptime </th><th>arrtime </th><th>classcode </th><th>status </th><th>jdate </th></tr><tr><td>" + name + "</td><td>" + number + "</td><td>" + ttime + "</td><td>" + deptime + " </td><td>" + arrtime + " </td><td>" + classcode + "</td><td>" + status + "</td><td>" + jdate +  "</td></tr></table>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM