使用表格HTML

时间:2015-11-05 09:35:35

标签: javascript jquery internet-explorer memory-leaks hta

早上好,

我在我的公司使用HTA,因为它们快速,脏,易于理解需要在需要时进行调整的任何其他人(我更喜欢NP ++到目前为止我使用的任何其他代码环境,但没有编译器)。

我已经制作了一个HTA(基于IE9,但在IE11中测试,因为它们是comapny标准),以向其他部门显示一些内部数据,这些数据将在需要时全天不定地更新。此数据在本地文本文件中创建,并使用ActiveXObject XMLHttp或XMLHttpRequest(如果可用)导入。问题是当表更新时,每次都会泄漏一点内存。

我原本以为是XML请求泄漏了,但是我已经把它固定到实际更新表的时候。

代码如下:

// Create the object arrays
var vData={}, vObject={}, vMethod={}, vEvent={};

// Function to update the table
vMethod.updateTable = function() {
    vData.fileName = 'out_comm/Data.txt';
    vData.fileText = '';
    try {
        vObject.rawFile = new XMLHttpRequest();
        vObject.rawFile.open('GET', vData.fileName, false);
        vObject.rawFile.onreadystatechange = function() {
            if (vObject.rawFile.readyState === 4) {
                if (vObject.rawFile.status === 200 || vObject.rawFile.status === 0) {
                    vData.fileText = vObject.rawFile.responseText;
                }
            }
        };
        vObject.rawFile.send();
    } catch (e) {
        try {
            vObject.rawFile = new ActiveXObject('Microsoft.XMLHTTP');
            vObject.rawFile.open('GET', vData.fileName, false);
            vObject.rawFile.onreadystatechange = function() {
                if (vObject.rawFile.readyState === 4) {
                    if (vObject.rawFile.status === 200 || vObject.rawFile.status === 0) {
                        vData.fileText = vObject.rawFile.responseText;
                    }
                }
            };
            vObject.rawFile.send();
        } catch (e) {
            alert('Error: ' + e.getMessage());
        }
    }
    delete vObject.rawFile;
    vData.tableHTML = '';
    vData.BlockCount = 0;
    vData.BlockNum = 1;
    vData.BlockLetter = 'A';
    vData.rowEven = true;
    vData.fileTextSplit = vData.fileText.split('\n');
    vData.tableHTML = '<table id="dataTable" cellspacing="0"><thead><tr><th></th><th></th><th></th><th></th>';
    vData.tableHTML = vData.tableHTML + '<th>5</th><th>4</th><th>3</th><th>2</th><th>1</th>';
    vData.tableHTML = vData.tableHTML + '<th>5</th><th>4</th><th>3</th><th>2</th><th>1</th>';
    vData.tableHTML = vData.tableHTML + '<th>5</th><th>4</th><th>3</th><th>2</th><th>1</th>';
    vData.tableHTML = vData.tableHTML + '<th>5</th><th>4</th><th>3</th><th>2</th><th>1</th>';
    vData.tableHTML = vData.tableHTML + '</tr></thead><tbody>';
    for (vData.arrayCount = 0;vData.arrayCount < vData.fileTextSplit.length; vData.arrayCount++) {
        if (vData.fileTextSplit[vData.arrayCount] !== '') {
            vData.fileTextLineSplit = vData.fileTextSplit[vData.arrayCount].split(',');
            if (vData.BlockCount == 4) {
                vData.BlockCount = 0;
                if (vData.rowEven) {
                    vData.rowEven = false;
                } else {
                    vData.rowEven = true;
                }
            }
            if (vData.rowEven) {
                vData.tableHTML = vData.tableHTML + '<tr id="item_' + vData.arrayCount + '" class="even">';
            } else {
                vData.tableHTML = vData.tableHTML + '<tr id="item_' + vData.arrayCount + '">';
            }
            vData.BlockCount ++;
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[0].substring(6, 8) + '/' + vData.fileTextLineSplit[0].substring(4, 6) + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>1A</td>';
            vData.tableHTML = vData.tableHTML + '<td>01</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[1] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td class="split">' + vData.fileTextLineSplit[2] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[3] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[4] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[5] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[6] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[7] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[8] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[9] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[10] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td>' + vData.fileTextLineSplit[11] + '</td>';
            vData.tableHTML = vData.tableHTML + '<td class="split">&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '<td>&pound;0</td>';
            vData.tableHTML = vData.tableHTML + '</tr>';
        }
    }
    vData.tableHTML = vData.tableHTML + '</tbody></table>';
    document.getElementById("dataTableDiv").innerHTML = '';
    document.getElementById("dataTableDiv").innerHTML = vData.tableHTML;

    delete vData.fileName;
    delete vData.tableHTML;
    delete vData.fileTextLineSplit;
    delete vData.rowEven;
    delete vData.fileTextSplit;
    delete vData.fileText;
    delete vData.BlockCount;
    delete vData.BlockNum;
    delete vData.BlockLetter;
    delete vObject.rawFile;
    delete vData.arrayCount;
};

我尝试使用纯javascript,jquery和两者的组合来清除表并重新导入数据,而不会减少内存使用量。

我还在学习,所以不是特别精通Java,所以我可能会遗漏一些简单的东西。我已经看过许多论坛(旧的但相关的),它们表明IE中的表总是有点不确定,但没有最新的,也没有实际的解决方案。它可能是导致问题的HTA环境,但由于一切都处于脱机状态,我无法证明它,因此我无法在IE中执行本地XML,因为安全性限制

非常感谢任何帮助

修改

快速编辑;我已经尝试过使用JQuerys .remove()和.empty()函数,但无济于事。 我将变量设置为对象数组(我认为术语是正确的)的原因是我能够使用delete函数,因为我认为它是占用内存的变量。

0 个答案:

没有答案