javascript - JSON data is not updated when i removing the dynamic row value in angularjs -


i implemented dynamic add , remove functionality in project.

add functionality working fine when deleting data based on checkbox selection , trying remove dynamic row json not updating.

<table class="table table-striped table-bordered">                      <tbody>                         <tr ng-repeat="personaldetail in forbearancemeasurelist">                             <td><input type="checkbox"                                 ng-model="personaldetail.selected" value="[$index]"/></td>                             <td width="300">                                 <div class="form-group">                                     <div class="form-group"                                         ng-class="{'has-error':!theform.measurecode.$valid && (!theform.$pristine || theform.$submitted),                                         'has-success':theform.measurecode.$valid && (!theform.$pristine || theform.$submitted)}">                                          <select class="form-control" ng-options="item item in a"                                             ng-model="formmodel.forbearancemeasure.measurecode[$index]"                                             name="measurecode" required="required"                                             ng-change="setrequired()">                                             <option value="">-- select code --</option>                                         </select>                                      </div>                                 </div>                             </td>                              <td width="300">                                 <div class="form-group">                                     <div class="form-group"                                         ng-class="{'has-error':!theform.measuretype.$valid && (!theform.$pristine || theform.$submitted),                                         'has-success':theform.measuretype.$valid && (!theform.$pristine || theform.$submitted)}">                                          <select class="form-control"                                             ng-options="item item in b[formmodel.forbearancemeasure.measurecode[$index]]"                                             ng-model="formmodel.forbearancemeasure.measuretype[$index]"                                             name="measuretype" required="required">                                             <option value="">-- select type --</option>                                         </select>                                     </div>                                 </div>                             </td>                             <td><textarea  class="form-control" ng-maxlength="1000"                                      ng-model="formmodel.forbearancemeasure.measuredescription[$index]"                                     name="measuredescription" id="textarea"                                     ng-required="textrequired[$index]"></textarea></td>                                     <td><input type="button" ng-click="remove()" value="remove" /></td>                          </tr>                     </tbody>                 </table> 

js file

$scope.formmodel = {                                 internationalclient : 0,                                 isconfidential : 0,                                 ismodificationlossrecog : 0,                                 idencomplianceforfindifficulty : 1,                                 idencomplianceforconcession : 1,                                 idencomplianceformodificationorrefin : 1,                                 forbearancemeasure : {                                      measuredescription : {                                      }                                 }                             };   $scope.forbearancemeasurelist = [ {} ];                              $scope.addnew = function(personaldetail) {                                  $scope.forbearancemeasurelist                                         .push({                                             /*                                              * 'mcode' : "", 'mtype' : "",                                              * 'comments' : "",                                              */                                              'measurecode' : $scope.formmodel.forbearancemeasure.measurecode,                                             'measuretype' : $scope.formmodel.forbearancemeasure.measuretype,                                             'measuredescription' : $scope.formmodel.forbearancemeasure.measuredescription,                                         });                                 console.log("$scope.forbearancemeasurelist:: "+ angular.tojson(                                         $scope.forbearancemeasurelist, false));                             };                              $scope.remove = function() {                                 var newdatalist = [];                                 $scope.selectedall = false;                                 var data1;                                  angular                                         .foreach(                                                 $scope.forbearancemeasurelist,                                                 function(selected) {                                                     if (!selected.selected) {                                                         console                                                                 .log("selected :: "                                                                         + selected);                                                         newdatalist                                                                 .push(selected);                                                      }                                                 });                                  $scope.forbearancemeasurelist = newdatalist;                             }; 

so need below output.

if json like.

    {"internationalclient":0,"isconfidential":0,"ismodificationlossrecog":0,"idencomplianceforfindifficulty":1,"idencomplianceforconcession":1,"idencomplianceformodificationorrefin":1, "forbearancemeasure":[ {"measurecode":"a-reduction of interest payable", "measuretype":"permanent", "measuredescription":"gfdgdf"}, { "measurecode":"c-reduction of repayment amounts", "measuretype":"temporary", "measuredescription":"ghgfdh" }, { "measurecode":"d-rescheduling repayment amounts", "measuretype":"temporary", "measuredescription":"hgfhgf" } ]} 

if want delete c 1 or 2 dynamic rows gui, json remove forbearancemeasure -->measuredescription -->measurecode-->measuretype index value based on selection gui.

{ {"internationalclient":0,"isconfidential":0,"ismodificationlossrecog":0,"idencomplianceforfindifficulty":1,"idencomplianceforconcession":1,"idencomplianceformodificationorrefin":1, "forbearancemeasure":[ {"measurecode":"a-reduction of interest payable", "measuretype":"permanent", "measuredescription":"gfdgdf"}, { "measurecode":"d-rescheduling repayment amounts", "measuretype":"temporary", "measuredescription":"hgfhgf" } ]} 

please provide me solution on this.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -