Send two lists by Json and Get it from Array on JavaScript -


i have 2 lists on controller , send lists array in json javascript.

see controller code here:

var aval = new list<avaliacaoviewmodel>(); aval = reldata.getavaliacao(data_1, data_2, cliente, operador);  var resumo = new list<resumoviewmodel>(); resumo = reldata.getresumo(data_1, data_2, cliente, operador);                 var result = new { aval = aval, resumo = resumo }; return json(result, jsonrequestbehavior.allowget); 

my list1 - controller-1

my list2 - controller-2

its working fine , can see 2 arrays on javascript:

$.ajax({             url: '/relatorios/avaloperador',             datatype: "json",             type: "get",             data: { 'data1': data1, 'data2': data2, 'operador': operador },             success: function (data) {               debugger;              var aval1 = avalia.getvalue(1);             var aval2 = avalia.getvalue(2);             var aval3 = avalia.getvalue(3);             var aval4 = avalia.getvalue(4); 

now need...

get data list1 (controller1) , put on 4 strings, like:

var avalia1 = column[1].tostring(); var avalia1 = column[2].tostring(); var avalia1 = column[3].tostring(); var avalia1 = column[4].tostring(); 

and second list/array pass html table

 <table class="table table-striped">      <thead>          <tr>              <th>cod</th>              <th>operador</th>              <th>qtde</th>              <th>pie </th>          <th>status</th>           </tr>      </thead>      <tbody>          <tr>              <td>3120</td>                                                         <td>patrick smith</td>              <td>2</td>                                                         <td><span class="pie">85/100</span></td>              <td>85%</td>                                                                                             </tr>                                                                         </tbody>  </table> 

console stringfy:

{"aval":[{"total":160,"avalia1":25,"avalia2":88.75,"avalia3":73.13,"avalia4":86.88}],"resumo":[{"cod":"1195","qtde":25,"result":62},{"cod":"1458","qtde":15,"result":73.33},{"cod":"1722","qtde":3,"result":58.33},{"cod":"2246","qtde":5,"result":65},{"cod":"2509","qtde":16,"result":62.5},{"cod":"2769","qtde":3,"result":100},{"cod":"2918","qtde":4,"result":68.75},{"cod":"3473","qtde":9,"result":66.67},{"cod":"5044","qtde":8,"result":81.25},{"cod":"5297","qtde":11,"result":65.91},{"cod":"5463","qtde":2,"result":100},{"cod":"5751","qtde":4,"result":75},{"cod":"5967","qtde":5,"result":75},{"cod":"6211","qtde":7,"result":60.71},{"cod":"6558","qtde":8,"result":53.13},{"cod":"7284","qtde":2,"result":75},{"cod":"7939","qtde":17,"result":67.65},{"cod":"7988","qtde":16,"result":76.56}]}

based on trincot's comment, found solution friend's help.

$.ajax({             url: '/relatorios/avaloperador',             datatype: "json",             type: "get",             data: { 'data1': data1, 'data2': data2, 'operador': operador },             success: function (data) {                  var aval1 = json.stringify(data.aval[0].avalia1);                 var aval2 = json.stringify(data.aval[0].avalia2);                 var aval3 = json.stringify(data.aval[0].avalia3);                 var aval4 = json.stringify(data.aval[0].avalia4);                  var resumo = "";                  (var in data.resumo) {                     resumo += "<tr>" +                         "<td>" + data.resumo[i].cod + "</td>" +                         "<td>" + data.resumo[i].qtde + "</td>" +                         "<td>" + data.resumo[i].result + "</td>" +                         "</tr>";                 }                                 $('#lbavalia1').html(aval1);                 $('#lbavalia2').html(aval2);                 $('#lbavalia3').html(aval3);                 $('#lbavalia4').html(aval4);                 $("#redumobody").html(resumo);              }, 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -