gpt4 book ai didi

javascript - 通过 Json 发送两个列表并在 JavaScript 上从 Array 获取它

转载 作者:搜寻专家 更新时间:2023-11-01 04:35:39 25 4
gpt4 key购买 nike

我的 Controller 上有两个列表,我将这些列表作为 ARRAY 在 json 中发送到 JavaScript。

在这里查看我的 Controller 代码:

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

它工作正常,我可以在 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);

现在我需要...

从list1(controller1)获取数据,放到4个字符串上,如:

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

然后第二个列表/数组将其传递给 HTML 表格

 <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>

控制台 Stringfy:

{“aval”:[{“总计”: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}]}

最佳答案

根据 trincot 的评论,我在 friend 的帮助下找到了解决方案。

$.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 = "";

for (var i 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);

},

关于javascript - 通过 Json 发送两个列表并在 JavaScript 上从 Array 获取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37503294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com