当前位置:   article > 正文

bootstrap-table新增行,数据清零问题_bootstraptable('insertrow')不刷新其他行

bootstraptable('insertrow')不刷新其他行

bootstrap-table新增行数据刷新

最近做项目有需要需要在bootstrap-table中新增行,这个官方有提供方法

insertRow
插入新行: $table.bootstrapTable('insertRow', {index: 1, row: row}).
  • 1
  • 2

但是出现一个问题,每次新增行之后,原本输入框的内容会被刷新(表格中嵌套了input框)

寻找也没有找到好的解决办法.最后只能用笨一点的,先获取表格的数据,存储起来,等新增之后在重新给表格赋值.

首先是获取行内数据.

var value=[]
var field=[]
//获取值
   		$('#table tr').each(function (i) {
            if ($(this).find('td:eq(1) input').val() !== undefined) {
                value.push(Number($(this).find('td:eq(1) input').val()))//获取第i行input框数据
            }
        });
//获取字段
        $("#table tr").each(function () {
            if ($(this).find('td:eq(1) input').val() !== undefined) {
                field.push($(this).find('td').eq(0).text());
            }
        });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在刷新之后给数据赋值

var count = $('#table').bootstrapTable('getData').length; //获取长度
        $('#table').bootstrapTable('insertRow', {index: count, row: {field: value, value: Input, weight: Input1}});//新增行
        $('#table tr').each(function (i) {
                if ($(this).find('td:eq(1) input').val() !== undefined) {
                    $(this).find('td:eq(1) input')[0].defaultValue = data[i]
                }
            }
        );
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/668921
推荐阅读
相关标签
  

闽ICP备14008679号