【问题标题】:Update Single row in on column using Jquery使用 Jquery 更新列中的单行
【发布时间】:2020-12-18 11:10:42
【问题描述】:

我正在使用带有 json 数据的 jquery 来填充 html 表,当我进行一些插入时,我只需要更新一列中的多行 但不工作她给我这样的数据'ttesttestetetetetetetete'

(NB) 班级领导是我在 html 表中的 td 班级

function RefreshTable(id) {
            $(document).ready(function () {
                $.ajax({
                    url: "/web_service/configuration.asmx/Update",
                    type: "GET",
                    dataType: "json",
                    data: { id, id},
                    contentType: "application/Json; Charset= Utf-8",
                    success: function (data) {
                        $('#myTable > tbody > tr > td.lead').empty();
                        $('#myTable > tbody > tr > td.lead').each(function () {
                            $.each(data.d, function (index, item) {
                                $('.lead').append(item[0][3]);
                            });
                        });
                    },
                    error: function (response) {
                        alert(response);
                    }
                });
            });
        }

我的数据是这样的

{"d":[[21,"Test 1"],[22,"Test 2"],[25,"Test 3"],[26,"Test 4"]]}

【问题讨论】:

    标签: jquery json ajax asp.net-ajax


    【解决方案1】:

    如果您发布数据示例会更容易。我们不需要调试你的ajax

    也许你的意思

    const data = {
      "d": [
        [21, "Test 1"],
        [22, "Test 2"],
        [25, "Test 3"],
        [26, "Test 4"]
      ]
    }
    
    
    function makeCells(data) {
      const html = data.d.map(item => `<tr><td class="lead">${item[1]}</td></tr>`).join('')
      console.log(html)
      $('#myTable > tbody').html(html);
    }
    makeCells(data)
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table id="myTable">
      <tbody></tbody>
    </table>

    【讨论】:

    • 非常感谢,但她给出了这个错误'Cannot read property 'join' of undefined'
    • 我需要一个你的数据对象的例子。只需更改任何个人数据
    • 您的数据中没有项目[0][3]。查看更新
    猜你喜欢
    • 2011-11-02
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 2012-02-27
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多