angular JS 实现增删改查

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        #myDiv, #myDiv1 {
            display: none;
        }

        table tr:first-of-type {
            background: #808080;
        }
    </style>
    <script src="../javascript/jquery-1.8.0.min.js"></script>
    <script src="../javascript/angular.min.js"></script>
    <script src="../javascript/dps.js"></script>

</head>
<body ng-controller="myController">
    <p>
        <input type="button" value="Add" id="add" ng-click="add()"/>
    </p>
    <table width="100%" align="center">
        <tr>
            <th>姓名</th>
            <th>性别</th>
            <th>生日</th>
            <th>身份证号</th>
            <th>电话</th>
            <th>地址</th>
            <th>email</th>
            <th>QQ</th>
            <th></th>
            <th></th>
        </tr>
        <tr style="text-align:center;" ng-repeat="item in items">
            <td ng-bind="item.xingming"></td>
            <td ng-bind="item.sex"></td>
            <td ng-bind="item.birth"></td>
            <td ng-bind ="item.sfz"></tdng-bind>
            <td ng-bind="item.tel"></td>
            <td ng-bind="item.dizhi"></td>
            <td ng-bind="item.emial"></td>
            <td ng-bind="item.qq"></td>
            <td><input type="button" value="Edit" ng-click="edit($index)" /></td>
            <td><input type="button" value="Delete" ng-click="delete($index)" /></td>
        </tr>
    </table>
    <div id="myDiv">
        <form id="EditForm">
            <table width="100%" align="center">
                <tr><th>姓名</th><th>性别</th><th>生日</th></tr>
                <tr style="text-align:center;">
                    <td><input type="text" ng-model="item.xingming" /></td>
                    <td><input type="text" ng-model="item.sex" /></td>
                    <td><input type="text" ng-model="item.birth"/></td>
                </tr>
                <tr>
                    <td colspan="3">
                        <input type="button" value="submit" id="submit"  ng-click="submit()"/>
                        <input type="button" value="cancel" id="cancel" ng-click="cancel()" />
                    </td>
                </tr>
            </table>
        </form>
    </div>



    <div id="myDiv1">
        <form id="EditForm1">
            <table width="100%" align="center">
                <tr><th>姓名</th><th>性别</th><th>生日</th></tr>
                <tr style="text-align:center;">
                    <td><input type="text" id="name" /></td>
                    <td><input type="text" id="sex" /></td>
                    <td><input type="text" id="birth" /></td>
                </tr>
                <tr>
                    <td colspan="3">
                        <input type="button" value="submit" id="submit1" ng-click="submit1()" />
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <script>
        $(function () {
            $("table tr:odd").css("background", "#eeeeee");
        });
        angular.module("myApp", [])
        .controller("myController", function ($http, $scope) {
            //数据呈现
            $http({
                method: 'get',
                url: '/Invoke.ashx',
                params: { m: "NLJMS.BusinessLayer$UserService$PageList", _parameters: $.toJSON([{ t: 16, d: "" }]) }
            }).success(function (msg) {
                $scope.items = msg.rows;
                var aa = 0;
                var bb = {};
                var arra = {};
                //更改
                $scope.edit = function (index) {
                    $("#myDiv").show();
                    $scope.item = msg.rows[index];
                    aa = index;//获取当前索引值
                    arra = $.extend(true, {},msg.rows);//实现数组的浅复制
                    bb = arra[index];//获取当前对象
                }
                $scope.submit = function () {
                    delete $scope.item.ui_user_org;
                    delete $scope.item.ui_user_role;
                    $http({
                        method: 'get',
                        url: '/Invoke.ashx',
                        params: { m: "NLJMS.BusinessLayer$UserService$Update", _parameters: $.toJSON([{ t: 90, m: "NLJMS.Models$ui_user", d: $scope.item }]) }
                    }).success(function () {
                        $("#myDiv").hide();
                    })
                }
                $scope.cancel = function () {
                    $("#myDiv").hide();

                    $scope.items[aa] = bb;
                  
                        //$http({
                        //    method: 'get',
                        //    url: '/Invoke.ashx',
                        //    params: { m: "NLJMS.BusinessLayer$UserService$PageList", _parameters: $.toJSON([{ t: 16, d: "" }]) }
                        //}).success(function (msg) {
                        //    $scope.items = msg.rows;
                        //})
                }
                //add
                $scope.add = function () {
                    $("#myDiv1").show();
                }
                $scope.submit1 = function () {
                    var json = {};
                    var name = $("#name").val();
                    var sex = $("#sex").val();
                    var birth = $("#birth").val();
                    json.sex = sex;
                    json.account = name;
                    json.password = name;
                    json.password1 = name;
                    json.xingming = name;
                    json.sfz = name;
                    json.tel = name;
                    json.email = name;
                    json.qq = name;
                    json.dizhi = name;


                    $http({
                        method: 'get',
                        url: '/Invoke.ashx',
                        params: { m: "NLJMS.BusinessLayer$UserService$Add", _parameters: $.toJSON([{ t: 90, m: "NLJMS.Models$ui_user", d: json }]) }
                    }).success(function () {
                        $("#myDiv1").hide();
                        $http({
                            method: 'get',
                            url: '/Invoke.ashx',
                            params: { m: "NLJMS.BusinessLayer$UserService$PageList", _parameters: $.toJSON([{ t: 16, d: "" }]) }
                        }).success(function (msg) {
                            $scope.items = msg.rows;
                        })
                    })
                }
                //delete
                $scope.delete = function (index) {
                    var id = msg.rows[index].id;
                    $http({
                        method: 'get',
                        url: '/Invoke.ashx',
                        params: { m: "NLJMS.BusinessLayer$UserService$DeleteList", _parameters: $.toJSON([{ t: 16, d: id }]) }
                    }).success(function () {
                        $http({
                            method: 'get',
                            url: '/Invoke.ashx',
                            params: { m: "NLJMS.BusinessLayer$UserService$PageList", _parameters: $.toJSON([{ t: 16, d: "" }]) }
                        }).success(function (msg) {
                            $scope.items = msg.rows;
                        })
                    })

                }

               
            })
        })
    </script>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值