2017-01-16 6 views
-1

これは私のプランカコードです。編集ボタンをクリックすると、詳細が編集されます。 Hereは私の完全なPlunkerプロジェクトへのリンクです。Angular Js JSON JavaScript、ボタンでjsonデータを編集

<title>Edit and Update JSON data</title> 
    <div> 
    {{myTestJson.name}} 
    <table><tbody> 
      <tr ng-repeat="(key, value) in myTestJson.MyTest[id].Main track by $index" > 
      <td><label>{{key}}: </label> 
     <input placeholder="" type="text" ng-model="myTestJson[key]"> 
      </td> 
       </tr> 
      </tbody> 
     </table> 
     <button value="Update and Save" id="saveButtonId" ng-click="saveUpdate()">Update/Save</button> 
    </div> 

答えて

0

これを試してみてください::

var myApp = angular.module('myApp', []); 

myApp.controller('studentController', function($scope, $http) { 
    var url = "Student.json"; 
    $http.get(url).success(function(response) { 
    $scope.students = response; 
    }); 

    $scope.removeEle = function(arra, index) { 
    arra.splice(index, 1); 

    }; 

}); 

    <div ng-controller="studentController"> 
    <h1>Student Information </h1> 

    <table> 
     <tr> 
     <th>Name</th> 
     <th>Roll No</th> 
     <th>Percentage</th> 
     </tr> 
     <tr ng-repeat="student in students"> 
     <td> 
      <input type="text" ng-model="student.Name" ng-show="student.edit"> 
      <span ng-hide="student.edit">{{ student.Name }}</span> 
     </td> 
     <td> 
      <input type="text" ng-model="student.RollNo" ng-show="student.edit"> 
      <span ng-hide="student.edit">{{ student.RollNo }}</span> 
     </td> 
     <td> 
      <input type="text" ng-model="student.Percentage" ng-show="student.edit"> 
      <span ng-hide="student.edit">{{ student.Percentage }}</span> 
     </td> 
     <td> 
      <button id="button2" ng-hide="student.edit" ng-click="student.edit = true">Edit</button> 
<button id="button4" ng-hide="student.edit" ng-click="removeEle(students, $index)">Delete({{$index}})</button> 
      <button id="button3" ng-show="student.edit" ng-click="student.edit = false">Submit</button> 
     </td> 
     </tr> 
    </table> 
    </div> 
+0

私はその後、いくつかのデータを削除したい場合は...? – Hari24

+0

私は答えを –

+0

更新ありがとうPankaj Badukale – Hari24

関連する問題