[英]jQuery not working without Alert()
Hi Everyone I have written a code to generate html Table from JSON file using jQuery. 大家好,我已经写了一个代码,使用jQuery从JSON文件生成html表。 but the code is not working when I remove the alert() function.
但是当我删除alert()函数时,代码不起作用。 Please help me out with the issue.
请帮我解决这个问题。 Thanking you all in advance
提前谢谢大家
Bellow is my code 波纹管是我的代码
<script>
var a = {};
var b = {};
var i = 1;
var inc = 0;
var j = 9;
$.getJSON(
'JsonDataBlocks.json',
function(data) {
a = data;
$.each(a, function(idx, elem) {
alert(inc);
if (idx == 0) {
$('table#tbl TBODY')
.append('<tr class="treegrid-' + i + ' treegrid-expanded"><td>' + elem.Tops + '</td><td><input type="text" class="info" value="' + elem.Jacket + '" id="' + i + 'a"></input></td><td><input type="text" class="info" value="' + elem.Flap + '" id="' + i + 'b"></input></td><td><input type="text" class="info" value="' + elem.Premium + '" id="' + i + 'c"></input></td><td><input type="text" class="info" value="' + elem.NonPrint + '" id="' + i + 'd"></input></td><td><input type="text" class="info" value="' + elem.Regular + '" id="' + i + 'e"></input></td></tr>');
i = i + 1;
} else {
$('table#tbl TBODY')
.append('<tr class="treegrid-' + i + ' treegrid-expanded" id="color"><td class="box">' + elem.Tops + '</td><td class="box"><input type="text" class="info" value="' + elem.Jacket + '" id="' + i + 'a"></input></td><td><input type="text" class="info" value="' + elem.Flap + '" id="' + i + 'b"></input></td><td><input type="text" class="info" value="' + elem.Premium + '" id="' + i + 'c"></input></td><td><input type="text" class="info" value="' + elem.NonPrint + '" id="' + i + 'd"></input></td><td><input type="text" class="info" value="' + elem.Regular + '" id="' + i + 'e"></input></td></tr>');
$.getJSON('TOI.json', function(data) {
b = data;
$.each(b, function(index, elem) {
if (elem.node == i) {
$('table#tbl TBODY').append('<tr id="colorBreak1" class="treegrid-' + j + ' treegrid-parent-' + i + '" ><td>' + elem.Tops + '</td><td><input type="text" class="info" value="' + elem.Jacket + '" id="' + j + 'a"></input></td><td><input type="text" class="info" value="' + elem.Flap + '" id="' + j + 'b"></input></td><td><input type="text" class="info" value="' + elem.Premium + '" id="' + j + 'c"></input></td><td><input type="text" class="info" value="' + elem.NonPrint + '" id="' + j + 'd"></input></td><td><input type="text" class="info" value="' + elem.Regular + '" id="' + j + 'e"></input></td></tr>');
j = j + 1;
}
});
i = i + 1;
});
}
});
});
</script>
<div id="scroll" class="col-xs-12">
<table id="tbl" class="tree table table-striped table-bordered">
<thead>
<tr>
<th class="header" href="">Tops</th>
<th class="header">Jacket</th>
<th class="header">Flap</th>
<th class="header">Premium</th>
<th class="header">Non Print</th>
<th class="header">Regular</th>
</thead>
<tbody></tbody>
</table>
</div>
</body>
</html>
Instead of: 代替:
$.getJSON(
'JsonDataBlocks.json',
function(data) {
use: 采用:
$.getJSON('JsonDataBlocks.json')
.done(data) { ... }
and do that for your subsequent $.getJSON call. 并为随后的$ .getJSON调用执行该操作。 $.getJSON is asynchronous, so nothing that relies on the data will work unless you implement it after the data is returned.
$ .getJSON是异步的,因此,除非您在返回数据后实现它,否则任何依赖于数据的工作都将无法进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.