js 動態獲取表格中的值並修改其他表格+js 動態拼接字符串

主要是用
思路是給表格設置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];
                        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章