赞
踩
最近做项目有需要需要在bootstrap-table中新增行,这个官方有提供方法
insertRow
插入新行: $table.bootstrapTable('insertRow', {index: 1, row: row}).
但是出现一个问题,每次新增行之后,原本输入框的内容会被刷新(表格中嵌套了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());
}
});
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]
}
}
);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。