等到previous .append()完成 [英] Wait until previous .append() is complete
问题描述
我们怎样才能让追加
等到previous 追加
已完成。我追加大量的数据所以present追加应该检查previous追加就完成了。我可以通过给所有用一些时间延迟追加的独立做到这一点。但实际上根据我的code我可能有'N'附加的号码,我要动态地做到这一点。
我试着用for或while循环,但剧本是越来越损坏,浏览器崩溃,因为接下来的追加开始前的previous追加就完成了。
$('#printall1')。点击(函数(){
$('#fourElementsonly')空();
变种cleartable = 0;
变种MAXLIMIT = 0;
VAR presentarraycount = 0;
$。员额(/ PortalUserReport / getjunkdata,空,函数(响应状态){
VAR报告=的eval(响应);
VAR totalRecordsCount = report.length; // 6000
VAR totalRecordsCountfortheLoop = totalRecordsCount;
变种arraycount = Math.ceil(totalRecordsCount / 1000);
VAR报告=新阵列(arraycount); //报告[6]
对于(VAR I = 0; I< arraycount;我++){
$('#fourElementsonly')追加('<表边框=1ID =Portal_User_elements'+ I +'的风格=边界崩溃:崩溃;宽度:800像素;保证金:0像素;填充:0像素;边框颜色:黑>< /表>');
}
报告[presentarraycount] =;
$。每个(报告功能(X){
如果(cleartable == 0){
对于(VAR I = 0; I< arraycount;我++){
$('#Portal_User_elements'+ I).empty();
}
cleartable ++;
}
如果(recordnumber< = totalRecordsCountfortheLoop){
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD风格= \\宽度:50像素;文本对齐:中心\\>中+ recordnumber +< / TD>< TD风格= \\宽度:350像素; \\>名称:+报告[X] .FirstName +< / TD&GT ;< TD风格= \\宽度:200像素; \\>用户名:+报告[X] .UserName +< / TD>< TD风格= \\宽度:200像素; \\>公司本着:+报告[X]。公司+< / TD>< / TR>中;
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD>< / TD>< TD>注册日期:其中,标签类= \\日期选择器\\>中+报告[X] .ActiveDate +< /标签>< TD>用户CN:+报告[X] .UserCN +< / TD>< TD>状态:+报告[X] .STATUS +< / TD>< / TD&GT ;&所述; / TR>中;
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD>< / TD>< TD>用户权限:+报告[X] .Privileges +< / TD>< TD>< / TD>&LT ; / TR>中;
MAXLIMIT ++;
如果(MAXLIMIT == 1000){
presentarraycount ++;
报告[presentarraycount] =;
MAXLIMIT = 0;
}
}
recordnumber ++;
});
对于(VAR I = 0; I< arraycount;我++){
$(本).delay(1000,函数(){
$('#Portal_User_elements'+ I).append(报道[I]);
});
}
});});
下面的解决方案正在所有浏览器IE6特别。在Firefox的响应时间是10秒,但是在IE6它是2分30秒。
$('#printall1')。点击(函数(){
$('#fourElementsonly')空();
变种cleartable = 0;
变种MAXLIMIT = 0;
VAR presentarraycount = 0; $。员额(/ PortalUserReport / getjunkdata,空,函数(响应状态){
VAR报告=的eval(响应); //我们有6000条记录的报告,现在
VAR totalRecordsCount = report.length; //数= 6000
VAR totalRecordsCountfortheLoop = totalRecordsCount;
变种arraycount = Math.ceil(totalRecordsCount / 1000);
VAR报告=新阵列(arraycount); //报告[6]
对于(VAR I = 0; I< arraycount;我++){
$('#fourElementsonly')追加('<表边框=1ID =Portal_User_elements'+ I +'的风格=边界崩溃:崩溃;宽度:800像素;保证金:0像素;填充:0像素;边框颜色:黑>< /表>');
}
报告[presentarraycount] =;
$。每个(报告功能(X){
如果(cleartable == 0){
对于(VAR I = 0; I< arraycount;我++){
$('#Portal_User_elements'+ I).empty();
}
cleartable ++;
} 如果(recordnumber< = totalRecordsCountfortheLoop){
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD风格= \\宽度:50像素;文本对齐:中心\\>中+ recordnumber +< / TD>< TD风格= \\宽度:350像素; \\>名称:+报告[X] .FirstName +< / TD&GT ;< TD风格= \\宽度:200像素; \\>用户名:+报告[X] .UserName +< / TD>< TD风格= \\宽度:200像素; \\>公司本着:+报告[X]。公司+< / TD>< / TR>中;
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD>< / TD>< TD>注册日期:其中,标签类= \\日期选择器\\>中+报告[X] .ActiveDate +< /标签>< TD>用户CN:+报告[X] .UserCN +< / TD>< TD>状态:+报告[X] .STATUS +< / TD>< / TD&GT ;&所述; / TR>中;
报告[presentarraycount] + =< TR风格= \\高度:20px的;边框:1px的纯黑色\\>< TD>< / TD>< TD>用户权限:+报告[X] .Privileges +< / TD>< TD>< / TD>&LT ; / TR>中;
MAXLIMIT ++;
如果(MAXLIMIT == 1000){
presentarraycount ++;
报告[presentarraycount] =;
MAXLIMIT = 0;
}
}
recordnumber ++;
}); 对于(VAR I = 0; I< arraycount;我++){
$('#Portal_User_elements'+ I).append(报道[I]);
}
});
});
How can we make append
wait until the previous append
is complete. I am appending huge amount of data so the present append should check if the previous append is complete. I am able to do this by giving all the append's independently with some time delay. But practically according to my code I may have 'n' number of appends so I want to do this dynamically.
I tried using for or while loop but the script is getting corrupted and the browser is crashing because the next append is starting before the previous append is complete.
$('#printall1').click(function() {
$('#fourElementsonly').empty();
var cleartable = 0;
var maxlimit = 0;
var presentarraycount = 0;
$.post("/PortalUserReport/getjunkdata", null, function(response, status) {
var report = eval(response);
var totalRecordsCount = report.length; //6000
var totalRecordsCountfortheLoop = totalRecordsCount;
var arraycount = Math.ceil(totalRecordsCount / 1000);
var reports = new Array(arraycount); // reports[6]
for (var i = 0; i < arraycount; i++) {
$('#fourElementsonly').append('<table border = "1" id = "Portal_User_elements' + i + '" style = " border-collapse:collapse; width:800px; margin:0px; padding:0px; border-color:black"> </table>');
}
reports[presentarraycount] = "";
$.each(report, function(x) {
if (cleartable == 0) {
for (var i = 0; i < arraycount; i++) {
$('#Portal_User_elements' + i).empty();
}
cleartable++;
}
if (recordnumber <= totalRecordsCountfortheLoop) {
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td style = \"width:50px; text-align:center \"> " + recordnumber + " </td> <td style = \"width:350px;\"> Name :" + report[x].FirstName + "</td> <td style = \"width:200px;\"> UserName :" + report[x].UserName + " </td> <td style = \"width:200px; \"> Company : " + report[x].Company + " </td> </tr>";
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td > </td> <td> Registration Date : <label class = \"datepicker\"> " + report[x].ActiveDate + " </label> <td> User CN : " + report[x].UserCN + " </td> <td> Status: " + report[x].Status + " </td> </ td> </tr>";
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td> </td> <td> User Privilege : " + report[x].Privileges + " </td> <td> </td> </tr>";
maxlimit++;
if (maxlimit == 1000) {
presentarraycount++;
reports[presentarraycount] = "";
maxlimit = 0;
}
}
recordnumber++;
});
for (var i = 0; i < arraycount; i++) {
$(this).delay(1000, function() {
$('#Portal_User_elements' + i).append(reports[i]);
});
}
});
});
The below solution is working on all the browsers especially IE6. The response time in Firefox is 10 sec, but in IE6 it is 2 min 30 sec.
$('#printall1').click(function() {
$('#fourElementsonly').empty();
var cleartable = 0;
var maxlimit = 0;
var presentarraycount = 0;
$.post("/PortalUserReport/getjunkdata", null, function(response, status) {
var report = eval(response);// we have 6000 records in the report now
var totalRecordsCount = report.length; // count = 6000
var totalRecordsCountfortheLoop = totalRecordsCount;
var arraycount = Math.ceil(totalRecordsCount / 1000);
var reports = new Array(arraycount); // reports[6]
for (var i = 0; i < arraycount; i++) {
$('#fourElementsonly').append('<table border = "1" id = "Portal_User_elements' + i + '" style = " border-collapse:collapse; width:800px; margin:0px; padding:0px; border-color:black"> </table>');
}
reports[presentarraycount] = "";
$.each(report, function(x) {
if (cleartable == 0) {
for (var i = 0; i < arraycount; i++) {
$('#Portal_User_elements' + i).empty();
}
cleartable++;
}
if (recordnumber <= totalRecordsCountfortheLoop) {
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td style = \"width:50px; text-align:center \"> " + recordnumber + " </td> <td style = \"width:350px;\"> Name :" + report[x].FirstName + "</td> <td style = \"width:200px;\"> UserName :" + report[x].UserName + " </td> <td style = \"width:200px; \"> Company : " + report[x].Company + " </td> </tr>";
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td > </td> <td> Registration Date : <label class = \"datepicker\"> " + report[x].ActiveDate + " </label> <td> User CN : " + report[x].UserCN + " </td> <td> Status: " + report[x].Status + " </td> </ td> </tr>";
reports[presentarraycount] += "<tr style = \"height:20px; border: 1px Solid Black\"> <td> </td> <td> User Privilege : " + report[x].Privileges + " </td> <td> </td> </tr>";
maxlimit++;
if (maxlimit == 1000) {
presentarraycount++;
reports[presentarraycount] = "";
maxlimit = 0;
}
}
recordnumber++;
});
for (var i = 0; i < arraycount; i++) {
$('#Portal_User_elements' + i).append(reports[i]);
}
});
});
这篇关于等到previous .append()完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!