Rumah  >  Artikel  >  hujung hadapan web  >  js动态添加删除,后台取数据(示例代码)_javascript技巧

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

WBOY
WBOYasal
2016-05-16 17:12:351069semak imbas

环境描述:就像你一般在论坛上发表文章,可能带附件,附件的数量是你手动添加删除的!!
/************************************************************************
*** 添加审批表单模板
************************************************************************/
// 增长的索引
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);
}
做了判断!!
如果还有不懂的人可以给我留言!!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn