【问题标题】:Editable rows is not working in table with JSON data?可编辑行不能在带有 JSON 数据的表中工作?
【发布时间】:2016-07-14 07:10:50
【问题描述】:

我解析了 JSON 对象并制作了一个表格结构来显示元素。我想让表格行可编辑。这是我用来形成表格的代码。

    (jsonDatag.data).forEach(function(item) {
                    var _tr = '<tr class="' + item.symbol + '"><td>' + item.symbol + '</td><td class="' + hclass + '">' + item.highPrice + '</td><td class="' + lclass + '">' + item.lowPrice + '</td><td class="' + oclass + '">' + item.openPrice + '</td><td class="' + ltclass + '">' + item.ltp + '</td><td>' + item.previousPrice + '</td><td>' + item.lastCorpAnnouncementDate + '</td></tr>'
                _tbody += _tr
            });
            _thead = _thead + _tbody;
            $('.mytable').html(_thead)
        }

现在我添加了这些行以使我的行可编辑,但它没有反映在我的输出中。

                  $('tr.'+item.symbol+'').each(function() {
                $(this).html('<input type="text" value="' + $(this).html() + '" />');
});

这里出了什么问题,我该如何纠正?

【问题讨论】:

    标签: javascript jquery css json html


    【解决方案1】:

    可编辑行在表格中不起作用

    这似乎令人困惑,因为它是可编辑的 td

    还有这个sn-p

    $('tr.' + item.symbol + '').each(function() {
      $(this).html('<input type="text" value="' + $(this).html() + '" />');
    });
    

    可能会放置一个input

    如果您希望制作可编辑的td,那么

    <td contenteditable="true">
    

    会起作用

    【讨论】:

    • 你是怎么设置的?
    • 我尝试直接对其进行硬编码并使用 attr 函数添加它也没有反映
    • 将它分配给 forEach 循环中的 td
    • 但是如果我想让表格在重新加载后也反映编辑后的值怎么办?我还要做什么??
    • @Karthykn 您已使用正在创建表的新值更新数据源
    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 2017-09-13
    • 2014-06-22
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多