当前位置:Gxlcms > JavaScript > js动态添加删除,后台取数据(示例代码)_javascript技巧

js动态添加删除,后台取数据(示例代码)_javascript技巧

时间:2021-07-01 10:21:17 帮助过:4人阅读

环境描述:就像你一般在论坛上发表文章,可能带附件,附件的数量是你手动添加删除的!!
/************************************************************************
*** 添加审批表单模板
************************************************************************/
// 增长的索引
var itemIndex = 1000;
// 数量
var counter = 0;
// 模板
var itemTemplate = '';
itemTemplate += '
';
itemTemplate += ' 表单字段';
itemTemplate += ' ';
itemTemplate += ' 值类型 ';
itemTemplate += ' ';
itemTemplate += '
';

// 添加
function addItem() {
var s = itemTemplate.replace(/#itemIndex#/g, itemIndex);
$("#divFormFields").append(s);
itemIndex ++;
counter ++;
}

// 删除
function delItem(index) {
$("#item_" + index).remove();
counter = counter - 1;
}


public class FlowFormConfigActionForm extends ActionForm {
private int id;
private String name;
private String processName;

private String formFillTemplatePath;
private String formShowTemplatePath;
private Map flowFormFieldCfgMap = new TreeMap();

/** 表单复杂属性 */
public FlowformFieldConfig getFlowFormFieldCfgElement(String key){
if(!flowFormFieldCfgMap.containsKey(key)){
flowFormFieldCfgMap.put(key, new FlowformFieldConfig());
}
return flowFormFieldCfgMap.get(key);
}

*U*****

public class FlowformFieldConfig {
private int id;
private String name;
private Class valueType;

主要要原理是:struts1.*在jsp显示的时候,会先从formbean里通过get***方法拿出属性的值!!


flowFormFieldCfgElement(#itemIndex#).name 这是核心,如果flowFormFieldCfgElement(#itemIndex#)为空的话,就会出错,所以在/** 表单复杂属性 */
public FlowformFieldConfig getFlowFormFieldCfgElement(String key){
if(!flowFormFieldCfgMap.containsKey(key)){
flowFormFieldCfgMap.put(key, new FlowformFieldConfig());
}
return flowFormFieldCfgMap.get(key);
}
做了判断!!
如果还有不懂的人可以给我留言!!

人气教程排行