Friday 15 May 2015

javascript - Creating nested object from divs -


I have an html page similar to the following: I want to read the fields and create the hierarchical JavaScript Object (or JSN). how to do this? Thanks for any help.

  & lt; Div class = "t" & gt; & Lt; Div & gt; & Lt; Div square = "c" & gt; & Lt; Input type = "text" & gt; & Lt; / Input & gt; & Lt; Input type = "text" & gt; & Lt; / Input & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "t" & gt; & Lt; Div & gt; & Lt; Div class = "t" & gt; & Lt; Div & gt; & Lt; Div square = "c" & gt; & Lt; Input type = "text" & gt; & Lt; / Input & gt; & Lt; Input type = "text" & gt; & Lt; / Input & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "result" & gt; & Lt; / Div & gt;   

The result of JSON should be displayed:

  "result": {"id": "", "ver": "", "name": In the order of nested element 'T' they are html / each input element under each class 'C' for each 'T': "", "Desc": "", "tdata". ]}    

to go through .t $ ('.t'). Each (function () {});

In input data for serializing . C :

  $ ('.c input'). Sort ();   

If you want to sneak up all the children and grandchildren:

  var nested elements = []; $ ("# Wrapper"). Search ("*"). Each (function () {nested elements; push (this);});    

No comments:

Post a Comment