Home >Web Front-end >JS Tutorial >js dynamically add and delete, get data in the background (sample code)_javascript skills
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 = '
//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
/**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! !