HTML

1. Agreement

    The HTML framework is used to generate HTML code, so there is a String toHtml() method.

2. Index model

    The index model of the HTML framework is xworker.html.Widgets.

3. Main model

    There can be multiple main models as needed. The main model needs to inherit xworker.html.Widgets. The code of the toHtml() method of the main model is as follows.

public static String toHtml(ActionContext actionContext){
     //Get the model
     Thing self = actionContext.getObject("self");
	
     //The main model sets the html code according to the situation
     String html = ...;
	
     //Code to generate child nodes
     for(Thing child : self.getChilds()){
         //Call the toHtml method of the child node to generate the code of the child node
         String childHtml = child.doAction("toHtml", actionContext);
		
         //Add to html code
         if(childHtml != null){
             html = html + "\n" = childHtml;
         }
     }
	
     //return html
     return html;
}

4. Video demonstration

    The following video demonstrates customizing an HTML component:

  • HelloHtml is a custom HTML component registered under the index model xworker.html.Widgets.
  • Html is the main model, which inherits the xworker.html.Widgets index model.
  • TestHtml is an instance object of Html, using the HelloHtml component.

 

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号