将学生数据添加到json并将学生信息编辑为不使用angularjs的json文件

时间:2014-08-27 01:13:30

标签: javascript django angularjs

JS:

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

myApp.controller("ctrl", function($scope, $http){

    $scope.loadData = function(){
        $http({
            url:"data/studentData.json",
            method:"GET"
        }).
        success(function(resp){
            $scope.studentInfo = resp;
        });


    };

    $scope.deleteStudent = function(currIndex){
        $scope.studentInfo.splice(currIndex,1);
    };

    $scope.editStudent = function(currIndex){
        $scope.studentInfo.push(sName,sBatch,sJoin,sGrad);
    };

    /* it was $scope.addStudent but i change it to addData*/

     $scope.addData = function(){
        $scope.studentInfo.push(sName,sBatch,sJoin,sGrad);
     }; 

    $scope.captureFormData = function(){
        $scope.studentInfo.push(tempObj);
        //in html <input ng-model="sName"/>
        //in html <input ng-model="sBatch"/>
        //in html <input ng-model="sJoin"/>

        var tempObj = {
            "name": $scope.sName,
            "batch": $scope.sBatch,
            "joinDate": $scope.sJoin,
            "gradDate": $scope.sGrad
        };
    }
});

0 个答案:

没有答案