【问题标题】:How to bind bind inner json list to html row jqMobile table如何将绑定内部 json 列表绑定到 html 行 jqMobile 表
【发布时间】:2013-11-29 22:31:54
【问题描述】:

只是我想知道如何将内部 json 列表“pslList”绑定到 html 行

    <table data-role="table" id="productOrders"  data-mode="reflow">
<thead>
                                <tr>
                                  <th>Code</th>
                                  <th>Name</th>
                                  <th>Price</th>
                                  <th>Qty.</th>
                                  <th>Ext</th>
                                </tr>
                              </thead>
                          <tbody>
                            <tr>
                              <th>1</th>
                              <td></td>
                              <td></td>
                              <td></td>
                              <td></td>
                              <td></td>
                            </tr>
                            </tbody>
                          </table>
json
    [
        {
            "amount": 12,
            "podate": "2013-11-28T00:00:00",
            "ponumber": 7,
            "pslList": [
                {
                    "ext": 210,
                    "ponumber": 7,
                    "prodcd": "ffrff",
                    "price": 70,
                    "prodname": "games",
                    "qty": 3
                },
                {
                    "ext": 70,
                    "ponumber": 7,
                    "prodcd": "rrfrr",
                    "price": 14,
                    "prodname": "DVDs",
                    "qty": 5
                }
            ],
            "vendorno": 1
        }
    ]

【问题讨论】:

    标签: javascript jquery json jquery-mobile html-table


    【解决方案1】:

    检索到 json 后,您可以遍历列表,创建行,然后将它们添加到表中:

    var $table = $('#productOrders tbody');
    var plist = json[0].pslList;
    for (i in plist) {
        var row = $('<tr><td>' + plist[i].prodcd + '</td><td>' + plist[i].prodname + '</td><td>' + plist[i].price + '</td><td>' + plist[i].qty + '</td><td>' + plist[i].ext + '</td></tr>');       
        $table.append(row);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2019-05-27
      相关资源
      最近更新 更多