双表的增删改查

<script type="text/javascript" src="js/angular.js"></script>
<script>
angular.module("myApp", [])
.controller("myCtrl", function($scope, $http) {
$http.get("http://result.eolinker.com/TucCTQueffdc1d1aaa3be05d8c62e9bb5d3e8b495f97cca?uri=hybrid")
.success(function(d) {
$scope.arr = d;
});
//年龄
$scope.cage = function(d) {
$scope.age = new Date().getYear() - new Date(d).getYear();
return $scope.age;
}
//全选   ng-model给数组家
$scope.ckall = function() {
for(d in $scope.arr) {
$scope.arr[d].ck = $scope.ckAll;
}
}


//按照部门查找
$scope.getM = function(d) {
if($scope.seldepart == "" || $scope.seldepart == undefined) {
return true;
}


if(d.indexOf($scope.seldepart) > -1) {
return true;
} else {
return false;
}
}


//添加
$scope.add = function() {
$scope.error = [];
if($scope.newname == "" || $scope.newname == undefined) {
$scope.sid = true;
$scope.error.push(1);
} else {
$scope.sid = false;
}



$scope.dep = "";
if($scope.newdepartment == "市场部") {
$scope.dep = {
"id": 1,
"name": "市场部"
}
} else {
$scope.dep = {
"id": 2,
"name": "研发部"
}
}


if($scope.error == 0) {
var s = {
"salary": $scope.newsalary,
"birthday": $scope.newbirthday,
"department": $scope.dep,
"gender": $scope.newgender,
"id": $scope.newid,
"name": $scope.newname
}
$scope.arr.push(s);
$scope.tian = false
}
}
});
</script>
</head>


<body ng-app="myApp" ng-controller="myCtrl">
<button ng-click="delAll()">批量删除</button>
<button ng-click="tian=true">添加</button>
<input id="sd" ng-model="seldepart" placeholder="根据部门模糊查询" />
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th><input type="checkbox" ng-model="ckAll" ng-click="ckall()" /> </th>
<th>id</th>
<th>name</th>
<th>age</th>
<th>gender</th>
<th>department</th>
<th>birthday</th>
<th>salary</th>
</tr>
<tr ng-repeat="d in arr" ng-show="getM(d.department.name)">
<th><input type="checkbox" ng-model="d.ck" /> </th>
<th>{{d.id}}</th>
<th>{{d.name}}</th>
<th>{{cage(d.birthday)}}</th>
<th>{{d.gender}}</th>
<th>{{d.department.name}}</th>
<th>{{d.birthday|date:"yyyy-MM-dd hh:mm:ss"}}</th>
<th>{{d.salary}}</th>
</tr>


</table>
<div ng-show="tian"><br />
<input type="number" ng-model="newid" /><br />
<input type="text" ng-model="newname" /><span ng-show="sid">请输入正确的用户名</span><br />
<!--select ng-model="newgender"> <br />
<option value="">请选择性别</option>
<option value="男">男</option>
<option value="女">女</option>
</select>-->
<input type="radio" checked="checked" ng-model="newgender" name="newgender" ng-checked="true" value="男" />男
<input type="radio" ng-model="newgender" name="newgender" value="女" />女
<br />
<select ng-model="newdepartment">
<option value="">请选择部门</option>
<option value="市场部">市场部</option>
<option value="研发部">研发部</option>
</select><br />
<input type="date" ng-model="newbirthday" /><br />
<input type="number" ng-model="newsalary" /><br />
<button ng-click="add()">保存</button><br />
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值