最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Populate table with jqueryjson - Stack Overflow

programmeradmin4浏览0评论

I have an asp web page and I want to populate the table with jquery, ajax web service call something. But I am not strong on it at all. The html part for the table is:

<tbody id="testBody">
            <tr id="templateEquipment" class="hidden">
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td class="hidden">
                </td>
            </tr>
        </tbody>

I already defined the columns and the table is empty at the beginning. And in jquery

function SearchEquipment() {
$.ajax({
    type: "POST",
    url: pageName + "SearchEquipment",
    data: "{'oParams':" + JSON.stringify(BeginSearch()) + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        if (response.d.length > 0) {

            $.each(response.d, function (i, item) {
            <!-- add row to fill the table-->

Thanks for your help. I do not have the resources for that(links are weled).

I have an asp web page and I want to populate the table with jquery, ajax web service call something. But I am not strong on it at all. The html part for the table is:

<tbody id="testBody">
            <tr id="templateEquipment" class="hidden">
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td class="hidden">
                </td>
            </tr>
        </tbody>

I already defined the columns and the table is empty at the beginning. And in jquery

function SearchEquipment() {
$.ajax({
    type: "POST",
    url: pageName + "SearchEquipment",
    data: "{'oParams':" + JSON.stringify(BeginSearch()) + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        if (response.d.length > 0) {

            $.each(response.d, function (i, item) {
            <!-- add row to fill the table-->

Thanks for your help. I do not have the resources for that(links are weled).

Share Improve this question asked Jul 13, 2012 at 12:58 user1108948user1108948
Add a ment  | 

1 Answer 1

Reset to default 6

You can do it like this.

var html = $.map(response.d, function (item, i) {
  return "<tr><td>" + item.value1 + "</td><td>" + item.value2 + "</td></tr>";
}).join("");

$("#testbody").append(html);

By creating a big string with all the rows and cells in it you only need to add it once to the DOM which is a lot quicker!

发布评论

评论列表(0)

  1. 暂无评论