【问题标题】:Showing Progress while Child row loads在子行加载时显示进度
【发布时间】:2016-09-29 04:39:49
【问题描述】:

再来一个问题:)

这一次我需要在加载子行时显示一些进度。由于有一个 Api 调用返回数据所需的时间相对较短,因此我确实想显示一些进度,除非单击父行的用户完全不知道是否有调用来查看其子行。

我做了什么:

我写了一个样式表类,它有一个

loader-small.gif

如下图:

tr.loading td.details-control {
    background: url('/Images/loader-small.gif') no-repeat center center;
}

并像这样应用:

$('#accountManagerEarningsDataTable tbody').on('click', 'td.details-control', function () {

        var tr = $(this).closest('tr');
        var row = table.row(tr);

        try {
            if (row.child.isShown()) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                //Calling the loading Class ------>
                tr.addClass('loading');

                // Open this row
                var arrForTable1 = [];
                var arrForTable2 = [];

                totalBrokerage = 0;
                totalRetailBrokerage = 0;
                totalSelfServiceBrokerage = 0;

                console.log('You selected: ' + row.data().AccountManagerID);

                var settings = {
                    "columnDefs": [
                    { targets: 1, align: "right", decimals: 0 },
                    { targets: 2, align: "right", decimals: 0 },
                    { targets: 3, align: "right", decimals: 0 },
                    { targets: 4, align: "right", decimals: 2 },
                    { targets: 5, align: "right", decimals: 2 }
                    ]
                };

                //problems with asynchoronus call back
                var response = organization_GetAccountManagerDetailEarningsAccountData(row.data(), purl2, pcontext);

                if (response.success === "true") {
                    for (var i = 0; i < response.value.length; i++) {

                        for (var j = 0; j < response.value[i].Securities.length; j++) {

                            var itemRow2 = {};
                            itemRow2["Security ID"] = response.value[i].Securities[j].SecurityId;
                            itemRow2["Trades"] = response.value[i].Securities[j].Trades;
                            itemRow2["Buy Qty"] = response.value[i].Securities[j].BuyQuantity;
                            itemRow2["Sell Qty"] = response.value[i].Securities[j].SellQuantity;
                            itemRow2["Total Brkg"] = response.value[i].Securities[j].Effective_Brokerage;
                            itemRow2["Online Brkg"] = response.value[i].Securities[j].Online_Brokerage;
                            arrForTable2.push(itemRow2);

                            totalBrokerage = totalBrokerage + parseFloat(response.value[i].Securities[j].Effective_Brokerage);
                            totalSelfServiceBrokerage = totalSelfServiceBrokerage + parseFloat(response.value[i].Securities[j].Online_Brokerage);
                        }

                        totalBrokerage = Math.round(totalBrokerage * 100) / 100;
                        totalSelfServiceBrokerage = Math.round(totalSelfServiceBrokerage * 100) / 100;
                        totalRetailBrokerage = Math.round(totalRetailBrokerage * 100) / 100;



                        var itemRow1 = {};
                        itemRow1["Account ID"] = response.value[i].AccountId;
                        itemRow1["Account Name"] = response.value[i].AccountName;
                        itemRow1["..."] = '<div class="alert alert-info" role="alert">' + buildHtmlTable(arrForTable2, 'table2x' + j, settings) + '<p>Total Brokerage ' + numberWithCommas(totalBrokerage) + '</p></div>';
                        arrForTable1.push(itemRow1);
                        arrForTable2 = [];

                        totalBrokerage = 0;
                        totalRetailBrokerage = 0;
                        totalSelfServiceBrokerage = 0;

                    }

                    tr.removeClass('loading');
                    htmlTable1 = buildHtmlTable(arrForTable1, 'table1x' + i);
                    row.child(htmlTable1).show();
                    tr.addClass('shown');
                }
                else {
                    row.child('<table><tr><td>' + response.value[0].AccountId + '</td></tr></table>').show();
                    tr.addClass('shown');
                };
            }
        } catch (e) {
            console.log(e.message);
        }

    });

问题:

Firefox 在用户点击后可以很好地显示进度图像,但 Edge 和 Chrome 不显示。当我从各自浏览器的开发者工具中调试时,两个浏览器都跨越了这段代码。

它的浏览器兼容问题?有解决办法吗?请帮帮我。

【问题讨论】:

  • 当来自服务器的响应返回时,进度条是否在 chrome 中显示一小段时间?像这样的 chrome 存在问题。如果这是问题,那么有修复。
  • @Nitheesh 它没有。
  • 请尝试分析器中提到的解决方案。我想它会解决你的问题。

标签: javascript jquery css asp.net-mvc datatables


【解决方案1】:

如果是 chrome,在进行服务器调用时显示加载栏时会出现这样的问题。请在拨打服务电话的地方进行以下更改。首先将类加载添加到表中

tr.addClass('loading');

然后通过提供超时功能进行服务调用

setTimeout(function(){
     var response = organization_GetAccountManagerDetailEarningsAccountData(row.data(), purl2, pcontext);
     ......
    //Your service calls and response call backs
},1);

在提供超时(比如 1 毫秒)时,Chrome 将获得将加载栏绑定到 DOM 的时间,否则 DOM 对象将无法显示微调器。

【讨论】:

  • 太棒了!至少现在显示了 gif 图像,但它在 google chrome 中没有动画;它保持静态。
  • 我认为这是 chrome 的问题。同样的问题也发生在这里。
  • Edge 还显示静态 *.gif 图像,但 firefox 保持乐观,一切正常。谢谢@Niteesh
猜你喜欢
  • 2011-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-24
  • 1970-01-01
  • 2016-12-22
  • 2011-07-22
  • 1970-01-01
相关资源
最近更新 更多