(前端)动态生成form表单

后端:form保存表单控件,entity保存表单数据

@RequiresPermissions("archcodeapplydetail:archcodeApplyDetail:view")
	@RequestMapping(value = "getFormByArchtypeid")
	@ResponseBody
	public Map getFormByArchtypeid(String archid,String tableid,String archtypeid, Map map) {
		String type = StringUtils.split(tableid, '_')[2];
		if ("project".equals(type)) {
			logger.info("project");
			SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
			map.put("form", sarchiveTypeTree.getProjconf());
			ProjectV project = projectVService.getOne(tableid, "0", archid);
			map.put("entity", project);
			return map;
		} else if ("volume".equals(type)) {
			logger.info("volume");
			SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
			map.put("form", sarchiveTypeTree.getVolconf());
			VolumeV volume = volumeVService.getOne(tableid, "0", archid);
			map.put("entity", volume);
			return map;
		} else if ("box".equals(type)) {
			logger.info("box");
			SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
			BoxV box = boxVService.getOne(tableid, "0", archid);
			map.put("entity", box);
			map.put("form", sarchiveTypeTree.getBoxconf());
			return map;
		} else if ("document".equals(type)) {
			logger.info("document");
			SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
			map.put("form", sarchiveTypeTree.getDocconf());
			DocumentV document = documentVService.getOne(tableid, "0", archid);
			map.put("entity", document);
			return map;
		} else {
			logger.info("else");
			return null;
		}
	}

前端

var form=data.form;
var entity=data.entity;
var v1=form.substring(1,form.length-1);
var v2=eval("(" + v1 + ")");
var content='';
		for (var i = 0; i < v2.length; i++) {
					var temp1='';
					var temp2='';
					for(var j in entity){
						if(j==v2[i].value){
							temp1='<div class="col-xs-3">' +
									'<div class="form-group">' +
									'<label class="control-label col-sm-4" title="">' +
									'<span class="required hide">*</span> '+v2[i].text+':<i class="fa icon-question hide"></i></label>' +
									'<div class="col-sm-8">' +
									'<input type="text" class="form-control" id="'+v2[i].value+'" name="'+v2[i].value+'" readonly="true" value="'+entity[j]+'">'+
									'</div>' +
									'</div>' +
									'</div>';
						}else {
							temp2='<div class="col-xs-3">' +
									'<div class="form-group">' +
									'<label class="control-label col-sm-4" title="">' +
									'<span class="required hide">*</span> '+v2[i].text+':<i class="fa icon-question hide"></i></label>' +
									'<div class="col-sm-8">' +
									'<input type="text" class="form-control" id="'+v2[i].value+'" name="'+v2[i].value+'" readonly="true" value="">'+
									'</div>' +
									'</div>' +
									'</div>';
						}

					}
					if(temp1!=''){
						content+=temp1;
					}
					else {
						content+=temp2;
					}
		}
				//填充表单
$('#inputForm').find('div').eq(0).html(content);

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值