I am new to AngularJS and am trying to make formatted JSON based on the values โโof the tr and td table.
The tr table is automatically generated. After submitting the form, I try to generate json values.
After submitting the form, I need to generate JSON.
<form> <table> <tr> <td> <input type="text" class="form-control" name="tname" value=""> </td> <td> <select ng-model="selection1" class="form-control" name="ttype" value=""> <option value="bbb" selected>Test</option> <option value="aaa" >Lumpsum</option> </select></td> <input type="text" class="form-control parsley-success" name="tvalue" > </td> </tr> <tr> <td> <input type="text" class="form-control" name="tname" value=""> </td> <td> <select ng-model="selection1" class="form-control" name="ttype" value=""> <option value="bbb" selected>Test</option> <option value="aaa" >Lumpsum</option> </select></td> <input type="text" class="form-control parsley-success" name="tvalue" > </td> </tr> <tr> <td> <input type="text" class="form-control" name="tname" value=""> </td> <td> <select ng-model="selection1" class="form-control" name="ttype" value=""> <option value="bbb" selected>Test</option> <option value="aaa" >Lumpsum</option> </select></td> <input type="text" class="form-control parsley-success" name="tvalue" > </td> </tr> <tr> <td> <input type="text" class="form-control" name="tname" value=""> </td> <td> <select ng-model="selection1" class="form-control" name="ttype" value=""> <option value="bbb" selected>Test</option> <option value="aaa" >Lumpsum</option> </select></td> <input type="text" class="form-control parsley-success" name="tvalue" > </td> </tr> </table> <input type="submit" name="save" value="save"/> </form>
I have a table with three rows, so I need to create 3 arrays of json objects
"data" : [ { "tname":"{tr1 name}", "value":"{tr1 tvalue}", "ttype":"{tr1 ttype}", "index":"index 1" }, { "tname":"{tr2 name}", "value":"{tr2 tvalue}", "ttype":"{tr2 ttype}", "index":"index 2" }, { "tname":"{tr3 tname}", "value":"{tr3 tvalue}", "ttype":"{tr3 ttype}", "index":"index 3" } ]
If I have 10 rows of a table, this means that I need to create a new row object.
Please can you suggest the correct way to do this in AngularJS?
source share