<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>
<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>