当表空时重新呈现表

时间:2016-02-19 09:44:33

标签: jquery html twitter-bootstrap datatable

我有桌子

<table class="table table-bordered responsive">
    <thead>
        <tr>
            <th class="head1">Address</th>
            <th class="head0">Date Time</th>
            <th class="head1">Admin Mobile</th>
            <th class="head0">Admin Name</th>
            <th class="head1"></th>
        </tr>
    </thead>
    <tbody id="hot-calls">
        <tr class="hidden">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td class="center"><button type="button" class="btn btn-primary call-btn" data-id=""><i class="iconfa-phone"></i> Call</button></td>
        </tr>
    </tbody>
</table>

使用setinterval我试图添加行

var used = ["3"];

function Adddata(Data) {
    for (var i = 0; i < Data.length; i++) {
        var tbody = jQuery("#hot-calls");
        var clone = tbody.find("tr.hidden").clone(true);
        clone.removeClass("hidden");
        clone.find("td:first").html(Data[i].location);
        clone.find("td:nth-child(2)").html(Data[i].calltime);
        clone.find("td:nth-child(3)").html(Data[i].mobile);
        clone.find("td:nth-child(4)").html(Data[i].adminName);
        clone.find("td:last > button").attr("data-id", Data[i].id);
        tbody.append(clone);
        used.push(Data[i].id);
    }
}
setInterval(function() {
    jQuery.post("http://www.hotel.shalvasoft.tk/admin/check-calls", {
        usedids: used
    }, function(res) {
        if (res != false) {
            console.log("exit");
            var resdata = JSON.parse(res);
            Adddata(resdata);
        }
    });
}, 10000);

如果在表中只有1行,则表明它是空的,但是如果表是空的,则不检查res != false

我该怎么做才能解决这个问题?

0 个答案:

没有答案