javascript - How to add Data to Specific index of json array using angularjs -


i created table data , edit button , getting problem when trying add edit data specific row.

here plunkr :- http://plnkr.co/edit/qkz7nu458i8il4olmayw?p=preview

here html page

    <table class="table table-bordered">                 <thead>                     <tr>                         <th><input type='checkbox' ng-modal='isall' ng-click='selectallrows()'></th>                         <th>id</th>                         <th>name</th>                         <th>edit</th>                      </tr>                 </thead>                 <tbody>                     <tr ng-repeat='p in person' ng-class="{'success':tableselection[$index]}">                         <td><input type='checkbox' ng-model='tableselection[$index]'></td>                         <td>{{p.id}}</td>                         <td>{{p.name}}</td>                         <td><button class='btn btn-primary' ng-click='edit(p.id)'><span class="glyphicon glyphicon-pencil"></span>edit</button></td>                     </tr>                 </tbody>              </table> <div ng-show='editabledata'>       <form role='form' class='form-horizontal'>          <div class='form-group'>       <label>id :-</label>       <input type='text' ng-model='pid' class='from-group col-sm-2'></div>       <div class='form-group'>       <label>name:-</label>       <input type='text' ng-model='pname' class='from-group col-sm-2'>       </div>       <button class='btn btn-primary' ng-click='saveeditdata(pid)'>save</button>       <button clas='btn btn-primary' ng-click='canceleditdata()'>cancel</button>       </form>     </div> 

here .js

$scope.person=[         {id:1,name:'devendher'},         {id:2,name:'macha'},         {id:3,name:'macha devendher'}         ];      $scope.editabledata=false;   $scope.edit=function(id){     $scope.editabledata=true;     for(i=0;i<$scope.person.length;i++){       if($scope.person[i].id==id)    {      $scope.pid=$scope.person[i].id;      $scope.pname=$scope.person[i].name;    }     }   }     $scope.saveeditdata=function(id){     for(i=0;i<$scope.person.length;i++){       if($scope.person[i].id==id){         $scope.person[i].push({'id':$scope.pid,'name':$scope.pname})       }     }     } 

i got error " $scope.person[i].push " not function there alternate way add data specific index of array?

i think mean:

$scope.person.push({...}) 

or

$scope.person[i] = {...} 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -