I am new to AngularJS, and am trying to make formatted JSON based on the table tr and td values.
The table tr is auto generated. Once the form is submitted, I try to generate the json values.
After the form is submitted, I need to generate the JSON.
<form>
<table>
<!-- Auto generated rows -->
<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 3 rows table, so I need to generate 3 object array the json
"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 table rows, that means I need to generate a new row object.
Please, can anyone suggest the correct way to do this in AngularJS?
auto generatedmean? Way are all theng-model's the same? Shouldn't have to do anything except grab one object assigned to allng-model's when they are set up properly, which they aren't. So main issue is how is table generated?trwhen it is being auto created.