在表格中显示JSON结果和“未定义"的内容 [英] Showing content of JSON result and 'undefined' in a grid
本文介绍了在表格中显示JSON结果和“未定义"的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在使用JQuery读取JSON并将其放入网格中.问题是:当JSON为时,网格将不会显示:
So, I'm using JQuery to read a JSON and put it inside a grid. Problem is : the grid won't show when the JSON is :
{"result":[[{"type":"VOMesas.TMesas","id":1,"fields":{ "FUsers":1,"FEnclosing":0,"FClientName":"","FCode":100,"FStatus":1,"FTotalValue":128.25}}]]}
但是,如果JSON是这样的,则不使用以下字段:{...}:
But if the JSON is like that, without the field:{...} :
{"result":[[{"type":"VOMesas.TMesas","id":1,"FUsers":1,"FEnclosing":0,"FClientName":"","FCode":100,"FStatus":1,"FTotalValue":128.25}]]}
它读取.
这是我正在使用的功能:
Here is the function I'm using:
function getContent(order) {
$.getJSON("query.json", function(data) {
$.each(data.result, function(i, item) {
var grid = '<table border="1">';
var i=0;
var CAMPO;
for (i=0; i < item.length; i++){
CAMPO = item[i];
grid += '<tr><td>'+ CAMPO.FQtdPessoas +
'</td><td>'+ CAMPO.FDataFechamento +
'</td><td>'+ CAMPO.FTempoPermanencia +
'</td><td>'+ CAMPO.FNomeCliente +
'</td><td>'+ CAMPO.FValorAcrescimo +
'</td><td>'+ CAMPO.FValorDesconto +
'</td><td>'+ CAMPO.FValorServico +
'</td><td>'+ CAMPO.FDataAbertura +
'</td><td>'+ CAMPO.FNumero +
'</td><td>'+ CAMPO.FStatus +
'</td><td>'+ CAMPO.FValorTotal +
'</td><td>'+ CAMPO.FTerminalAberto +
'</td><td>'+ CAMPO.FNumeroVenda +
'</td><td>'+ CAMPO.FGarcon +
'</td></tr>';
}
grid += '</table>';
$("#dvContent").html(grid);
$("#dvContent").find("a").click(function(e){
var link = $(this);
getContent(link.html());
});
});
});
}
$(document).ready(function(){
$(function() {
getContent();
});
});
推荐答案
问题似乎出在您要忽略的代码中:
Looks like the problem is in the code you're omitting:
grid += '<tr><td>'+ ........ +'</td></tr>';
如果json结果为第一种格式,则您应该能够使用CAMPO.fields
访问fields
对象.
If the json result is in the first format, then you should be able to access the fields
object using CAMPO.fields
.
示例:
grid += '<tr><td>'+ CAMPO.fields.FQtdPessoas +'</td><td>'+ CAMPO.fields.FDataFechamento +'</td><td>'+ [...]
这篇关于在表格中显示JSON结果和“未定义"的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文