Home  >  Article  >  Web Front-end  >  js dynamically add and delete, get data in the background (sample code)_javascript skills

js dynamically add and delete, get data in the background (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:12:351069browse

Environment description: Just like you usually publish an article on the forum, you may have attachments. The number of attachments is manually added and deleted by you! !
/***************************************************** ************************
*** Add approval form template
************************ *************************************************** *****/
// Growing index
var itemIndex = 1000;
// Quantity
var counter = 0;
// Template
var itemTemplate = '';
itemTemplate = '

';
itemTemplate = ' Form field';
itemTemplate = ' ';
itemTemplate = ' Value type';
itemTemplate = ' ';
itemTemplate = '
';

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

//Delete
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();

/**Form complex properties*/
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;

The main principle is: when struts1.* is displayed in jsp, it will first take out the attribute value from the formbean through the get*** method! !


flowFormFieldCfgElement(#itemIndex#).name This is the core. If flowFormFieldCfgElement(#itemIndex#) is empty, an error will occur, so in /**Form complex properties*/
public FlowformFieldConfig getFlowFormFieldCfgElement( String key){
if(!flowFormFieldCfgMap.containsKey(key)){
flowFormFieldCfgMap.put(key, new FlowformFieldConfig());
}
return flowFormFieldCfgMap.get(key);
}
Made a judgment! !
If anyone still doesn’t understand, please leave me a message! !

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn