Automatically generate HTML from JSON

后端 未结 5 1917
夕颜
夕颜 2020-12-14 01:58

I am working on a template system. I imagine that as a regular user you can create a. json file, and based on that file the system will automatically generate html. I am fai

5条回答
  •  渐次进展
    2020-12-14 02:55

    @topherg

    • It is faster to bind obj to parent earlier - direct after createElement.

    • When you come to object.children you should check:

      if(object.children.constructor===Array){
        for(var i=0;i

      Otherwise no array will be parsed.

    • SetAttribute is slow but sometimes you need it for (name,item*,data-*,rel,objekt,param,loop,datetime,style[if you don't want to parse an additional object],colspan,...). Direct Set Attribute (element.style.width="100px";) is 88 times faster (jsPerf).

    To create ONE DOM element is faster than innerHTML. Building a DOM tree directly, takes double time of innerHTML. Even innerHTML is very fast that kind of DOM parsing is still fast too.

提交回复
热议问题