1. 表格内改变input值不生效
$('#bootstrap-table tr td input').on('change',function(e){
var value = $(this).val();
$(this).attr("value",value);
});
2. 取表格当前行当前列
$('#bootstrap-table tr td input').blur(function(e){
var $this = $(this);
var $td = $this.parent();
var indextd = $td.index();
if(indextd == '2'){
var value = $(this).val();
var fullName = pinyin.getFullChars(value);
var $tr = $this.parent().parent();
var index = $tr.data('index');
$('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(3) input').attr("value",fullName);
}
});
3. input赋值
$('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(3) input').attr("value",fullName);
4. input取值
var value = $('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(3) input').attr("value");
5. json转字符串存到input框
var json_t = [{
"title": "",
"name": "",
"datatype": "",
"params": "",
}];
var objJson= JSON.stringify(json_t).replace(/\"/g, "'");
$('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(5) input').attr("value",objJson);
6. input框加显示隐藏事件
$('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(6) a').hide();
$('#bootstrap-table'+' tr[data-index="' + index + '"] td:eq(5) input').show();
7. input文本加onclick事件(尽量使用单引号)
{
align: 'center',
title: '操作',
formatter: function(value, row, index) {
var srow = JSON.stringify(row.params);
var objJson = srow.replace(/\"/g, "'");
if(row.datatype == 'Table') {
var html = $.common.sprintf('<a class="btn btn-info btn-xs" href="javascript:void(0)" οnclick="detail('+objJson+'\,'+index +'\,\''+row.title+'\')"><i class="fa fa-list-ul"></i>列表</a> ');
return html;
} else {
var html = $.common.sprintf('<a class="btn btn-info btn-xs" href="javascript:void(0)" style="display: none;" οnclick="detail('+objJson+'\,'+index +'\,\''+row.title+'\')"><i class="fa fa-list-ul"></i>列表</a> ');
return html;
}
}
}
8. json传给后台get请求(注意转码)
function detail(row,index,title) {
var tit = encodeURIComponent(title);
var srow = encodeURIComponent(JSON.stringify(row));
var url = prefix + '/detail/'+index+'?title='+tit+'¶m='+srow;
var options = {
title: '列表模板',
url: url,
callBack: doSubmit
};
$.modal.openOptions(options);
}
9. 父子组件传值(与8一起看)
function doSubmit(index, layero){
var table = $.modal.getChildFrame(index).find("#bootstrap-table");
var jsonTable=tableToJson(table);
var parentId = $.modal.getChildFrame(index).find("#parentId").val();
var title = $.modal.getChildFrame(index).find("#titleTable").val();
var srow = JSON.stringify(jsonTable);
var objJson = srow.replace(/\"/g, "'");
$('#bootstrap-table'+' tr[data-index="' + parentId + '"] td:eq(5) input').attr("value",objJson);
$('#bootstrap-table'+' tr[data-index="' + parentId + '"] td:eq(6) a').attr('onclick','detail('+objJson+'\,'+parentId +'\,\''+title+'\')');
$.modal.close(index);
}
10. 表格转json
function tableToJson(table) {
var json = [];
var rows = table.find("tr");
for (var i = 1; i < rows.length; i++) {
var row = rows.eq(i);
var cols = row.find("td");
var rowData = {};
for (var j = 2; j < cols.length; j++) {
var col = cols.eq(j).children(':first');
if( cols.eq(j).find("a").length > 0 ){
continue;
}
var name = col.attr("name");
var value = col.attr("value");
if( cols.eq(j).find("select").length > 0 ){
value= col.find('option:selected').val();
}else{
if(name == 'params'&&cols.eq(4).find('option:selected').val() =='Table'){
var newstr = col.attr("value").replace(/'/g, '"');
value = JSON.parse(newstr);
}else{
value = col.attr("value");
}
}
rowData[name] = value;
}
json.push(rowData);
}
return json;
}
11. 字符串转json
var newstr = col.attr("value").replace(/'/g, '"');
var value = JSON.parse(newstr);
12. 字符串转数字
var indexTable=[[${indexTable}]];
var titleTable=[[${titleTable}]];
$("h4").html("序号"+(Number(indexTable)+1)+ ":" + titleTable);
|