angular增删改查,json文件格式

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/angular.js" ></script>
        <script>
            var app=angular.module("myApp",[]);
            app.controller("myCtrl",function($scope,$http){
                $scope.kong=false;
                $http.get("http://result.eolinker.com/TucCTQueffdc1d1aaa3be05d8c62e9bb5d3e8b495f97cca?uri=hybrid")
                .success(function(aaa){
                    $scope.pros=aaa;
                });
                $scope.getage=function(time){
                    var m=new Date(time).getYear();
                    var n=new Date().getYear();
                    return n-m;
                }
                $scope.qx=function(){
                    for(index in $scope.pros){
                        $scope.pros[index].state=$scope.xuan;
                    }
                }
                $scope.delete=function(i){
                    for(index in $scope.pros){
                        if($scope.pros[index].id==i){
                            $scope.pros.splice(index,1);
                        }
                    }
                    if($scope.pros.length==0){
                        $scope.kong=true;
                    }
                }
                $scope.cha=function(dname){
                    if($scope.dn=="" || $scope.dn==undefined){
                        return true;
                    }else if(dname.indexOf($scope.dn)>-1){
                        return true;
                    }
                    return false;
                }
                $scope.deleteall=function(){
                    for(var i=0; i<$scope.pros.length; i++){
                        if($scope.pros[i].state){
                            $scope.pros.splice(i,1);
                            i--;
                        }
                    }
                    if($scope.pros.length==0){
                        $scope.kong=true;
                    }
                }
                $scope.isshow=false;
                $scope.add=function(){
                    $scope.arr=[];
                    var id=0;
                    for(index in $scope.pros){
                        if($scope.pros[index].id>id){
                            var id=$scope.pros[index].id
                        }
                    }
                    var newid=id+1;
                    var newname=$scope.add_name;
                    if(newname=="" || newname==undefined){
                        $scope.arr.push(1);
                        $scope.nn=("员工姓名不能为空");
                    }else{
                        $scope.nn="";
                    }
                    var newgender=$scope.add_gender;
                    if(newgender=="" || newgender==undefined){
                        $scope.arr.push(2);
                        $scope.gg=("员工性别不能为空");
                    }else{
                        $scope.gg="";
                    }
                    var newmoney=$scope.add_money;
                    if(newmoney=="" || newmoney==undefined){
                        $scope.arr.push(3);
                        $scope.ss=("员工薪资不能为空");
                    }else{
                        $scope.ss="";
                    }
                    var newbirthday=$scope.add_birthday;
                    if(newbirthday=="" || newbirthday==undefined){
                        $scope.arr.push(4);
                        $scope.bb=("出生日期不能为空");
                    }else{
                        $scope.bb="";
                    }
                    var obj;
                    if($scope.dname=="" || $scope.dname==undefined){
                        $scope.arr.push(5);
                        $scope.dd=("部门不能为空")
                    }else if($scope.dname=="市场部"){
                        obj={id:1,name:$scope.dname};
                        $scope.dd="";
                    }else if($scope.dname=="研发部"){
                        obj={id:1,name:$scope.dname};
                        $scope.dd="";
                    }
                    if($scope.arr.length==0){
                        $scope.pros.push({
                            id:newid,
                            name:newname,
                            gender:newgender,
                            salary:newmoney,
                            birthday:newbirthday,
                            department:obj
                        });
                        $scope.isshow=false;
                    }
                }
            });
        </script>
    </head>
    <body ng-app="myApp" ng-controller="myCtrl">
        <center>
            <input type="text" placeholder="根据姓名模糊查询" ng-model="n"/>
            <input type="text" placeholder="根据部门模糊查询" ng-model="dn"/>
            <select ng-model="pai">
                <option value="">根据薪资排序</option>
                <option value="+salary">升序</option>
                <option value="-salary">降序</option>
            </select>
            <button ng-click="deleteall()">批量删除</button>
            <button ng-click="isshow=true">添加</button><br/>
        <table border="1px" cellpadding="10" cellspacing="0">
            <thead>
                <th><input type="checkbox" ng-click="qx()" ng-model="xuan" ng-hide="kong"></th>
                <th>员工编号</th>
                <th>员工姓名</th>
                <th>员工年龄</th>
                <th>员工性别</th>
                <th>员工薪资</th>
                <th>出生日期</th>
                <th>部门名称</th>
                <th>操作</th>
            </thead>
            <tbody>
                <tr ng-repeat="pro in pros | orderBy:'-birthday' | filter:{name:n} | orderBy:pai" ng-show="cha(pro.department.name)" ng-show="yue(pro.birthday)">
                    <td><input type="checkbox" ng-model="pro.state"></td>
                    <td>{{pro.id}}</td>
                    <td>{{pro.name}}</td>
                    <td>{{getage(pro.birthday)}}</td>
                    <td>{{pro.gender}}</td>
                    <td><span ng-hide="update">{{pro.salary | currency:"¥"}}</span><span ng-show="update"><input type="text" ng-model="pro.salary"><button ng-click="update=false">保存</button></span></td>
                    <td>{{pro.birthday | date:"yyyy-MM-dd hh:mm:ss"}}</td>
                    <td>{{pro.department.name}}</td>
                    <td>
                        <button ng-click="update=true">修改</button>
                        <button ng-click="delete(pro.id)">删除</button>
                    </td>
                </tr>
            </tbody>
        </table>
        <p ng-show="kong">无操作数据</p>
        <form ng-show="isshow">
            <input type="text" placeholder="员工姓名" ng-model="add_name"/><span ng-if="nn.length!=0">{{nn}}</span><br/>
            <input type="radio" value="男" ng-model="add_gender"/>男
            <input type="radio" value="女" ng-model="add_gender"/>女
            <span ng-if="gg.length!=0">{{gg}}</span><br/>
            <input type="text" placeholder="员工薪资" ng-model="add_money"/><span ng-if="ss.length!=0">{{ss}}</span><br/>
            <input type="date" placeholder="出生日期" ng-model="add_birthday"/><span ng-if="bb.length!=0">{{bb}}</span><br/>
            <select ng-model="dname">
                <option value="">请选择部门</option>
                <option value="研发部">研发部</option>
                <option value="市场部">市场部</option>
            </select>
            <span ng-if="dd.length!=0">{{dd}}</span><br />
            <button ng-click="add()">保存</button>
        </form>
        </center>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/aa15362415/article/details/79102891