主要是用
思路是给表格设置id,取 表格tr 的值
$('#'+d+"DataOptions" +" tr").each(function(i){
var fieldName = $(this).find('td:eq(0)').attr("name");
}
需求是,点击右侧表格的操作按钮,把值叠加到左侧中
//获取右侧当前数据项选中的列表
// var fieldParams = []
var rightMap = new Map(); // 右侧点击map
$('#'+recordId+"DataOptions" +" tr").each(function(i){
var fieldName =$(this).find('td:eq(0)').attr("name");
if(fieldName!=null &&fieldName!=undefined){
var fieldValue =$(this).find('td:eq(1)').text()
if(fieldValue == ''||fieldValue == null){
fieldValue=0
}
}
rightMap.set(fieldName,fieldValue);
// fieldParams.push({[fieldName]:fieldValue});
});
//获取左侧的数据项选中的列表
var leftMap = new Map();
$("#ownTypeField tr").each(function(i){
//var ch = $(this).find('td:eq(4) input').val();//取表格的第i行第四列的input标签的值
var id =$(this).attr('id')
if(id!=null &&id!=undefined){
var value =$(this).find('td:eq(1) input').val()
if(value == ''||value == null){
value=0
}
leftMap.set(id,value);
}
});
//最后上传的集合
var updateMap = new Map();
//修改左边的Map集合并
for (var [key, value] of leftMap) {
//左侧的值
var leftValue = $("#"+key+"Input").val();
//右侧的值
var rightValue = rightMap.get(key);
if(leftValue<0){
leftValue=0;
}
if(rightValue<0){
rightValue=0;
}
var fianlValue = 0
if(auditStatus==1){
//1通过
fianlValue = parseInt(leftValue)+parseInt(rightValue);
}else if(auditStatus== 2){
//2.撤回
fianlValue = parseInt(leftValue)-parseInt(rightValue);
}
//赋值
updateMap.set(key,fianlValue);
$("#"+key+"Input").val(fianlValue);
}
/**
* Map转json
* @param m
* @returns String
*/
function MapTOJson(m) {
var str = '[';
var i = 1;
m.forEach(function (item, key, mapObj) {
if(mapObj.size == i){
str += '{"'+ key+'":"'+ item + '"}';
}else{
str += '{"'+ key+'":"'+ item + '"},';
}
i++;
});
str +=']';
//console.log(str);
return str;
}
//拼接字符串
var dataTable="<table border=\"0\" style=\"width: 100%;\">";
dataTable+= "<td height=\"200\" >";
dataTable+= "<table border=\"1\" style=\"width: 100%;height: 100%;\" >";
//判断对象不为空
if(ownRecord != null && ownRecord != undefined && ownRecord != '' && ownRecord.sendStatus===0) {
//对象的属性不为空 if(ownRecord.workProgress!=null&&ownRecord.workProgress!=undefined&&ownRecord.workProgress!=''){
dataTable+= ownRecord.workProgress
}
}
//集合不为空 if(ownTypefieldlist!=null&&ownTypefieldlist.length>0&&ownTypefieldlist!=undefined&&ownTypefieldlist!=""){
}
//for循环
for (var i = 0; i < lowerSubordlist.length; i++) {
var recordData = lowerSubordlist[i];
}