How can I deserialize a multilevel JavaScript object to an HTML form? -


edit: there 1 conceptual error , 1 technical error on problem definition question should better closed instead of sanitized. when have time redefine problem i'll post again. please voting close because of unspecific.

there lots of info , questions serializing complex html forms corresponding javascript object (for example this).

here sample of process: having form

<form>     <input type="text" name="scalar" value="1">     <input type="text" name="array[0]" value="1">     <input type="text" name="array[1]" value="2">     <input type="text" name="array[2]" value="3">     <input type="text" name="object[subscalar]" value="1"> </form> 

and getting javascript object

{   "scalar": 1,   "array": [1, 2, 3],   "object": {     "subscalar": 1   } } 

but how can inverse job?

our goal perform native post targeting separate browser window. have complex javascript object , sending through ajax post, using object directly jquery.ajax data parameter. need create real form in dom containing inputs , values brackets syntax, , natively submit targeting specific frame.

jquery usage optional. existing method, library, etc preferable against custom snuppet. isn't not being able code it, it's not being sure need reinvent wheel.

thanks in advance.

function parseform(elem,parent=""){     this.html="";     this.parent=parent;     if(typeof elem=="array"){         var counter=0;         elem.foreach(function(a){             this.html+=new parseform(a,this.parent+"["+counter+"]").html;             counter++;         });     }     if(typeof elem=="string"){         this.html+="<input name='"this.parent+"["+elem+"]' />";     }     //object in progress     if(typeof elem=="object"){         (var key in elem) {              if (p.hasownproperty(key)) {                  this.html += new parseform(elem[key],this.parent="["+key+"]").html;             }         }     } } 

use this:

 code=new parseform(yourjsondecoded).html; 

i know dont want code, dont think theres api specific


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -