标签:分层 数组 创建 mamicode 信息 dex asc 收购 update
angular介绍:
baseController:
//基本控制层
app.controller(‘baseController‘ ,function($scope){
$scope.reloadList=function(){
//切换页码
//$scope.findPage($scope.paginationConf.currentPage,$scope.paginationConf.itemsPerPage)
$scope.search($scope.paginationConf.currentPage,$scope.paginationConf.itemsPerPage)
}
$scope.paginationConf = {
currentPage: 1,
totalItems: 10,
itemsPerPage: 10,
perPageOptions: [10,20,30,40,50],
onChange: function () {
$scope.reloadList();
}
}
/*$scope.findPage = function(page,rows){
$http.get(‘http://localhost:9101/brand/findPage.do?page=‘+page+‘&rows=‘+rows).success(
function (response) {
$scope.list = response.rows;
$scope.paginationConf.totalItems = response.total;
}
)
}*/
//添加数据
/*$scope.add = function(){
$http.post(‘http://localhost:9101/brand/add.do‘,$scope.entity).success(
function (response) {
if (response.success == true){
$scope.reloadList();
} else{
alert(response.message);
$scope.reloadList();
}
}
)
}*/
//定义一个数组
$scope.selectedIds=[];
$scope.updateSelection = function($event,id){
if ($event.target.checked){
$scope.selectedIds.push(id);
}else{
var index = $scope.selectedIds.indexOf(id);
$scope.selectedIds.splice(index,1);
}
}
});
xxxService:
app.service(‘brandService‘,function ($http) {
//分页查询
this.search = function (page,rows,searchEntity) {
return $http.post(‘http://localhost:9101/brand/search.do?page=‘+page+‘&rows=‘+rows,searchEntity);
}
//删除选中数据
this.dele = function (selectedIds) {
return $http.get(‘http://localhost:9101/brand/delete.do?ids=‘+selectedIds);
}
//查询某一条数据
this.findOne = function (id) {
return $http.get(‘http://localhost:9101/brand/findOne.do?id=‘+id);
}
//保存
this.save = function (methodName,entity) {
return $http.put(‘http://localhost:9101/brand/‘+methodName+‘.do‘,entity);
}
})
xxxController:
//定义控制层,需要注入service代码
app.controller(‘brandController‘,function ($scope,$controller,brandService) {
$controller(‘baseController‘,{$scope:$scope});//继承
//删除所有选中信息
$scope.dele = function(){
brandService.dele($scope.selectedIds).success(
function (response) {
if (response.success == true){
$scope.reloadList();
} else{
alert(response.message);
$scope.reloadList();
}
}
)
}
//修改前查询要修改的数据
$scope.findOne = function(id){
brandService.findOne(id).success(
function (response) {
$scope.entity = response;
}
)
}
//保存修改后的数据
$scope.save = function(){
var id = $scope.entity.id;
var methodName = "add";
if (id != null){
methodName = "update";
}
brandService.save(methodName,$scope.entity).success(
function (response) {
if (response.success == true){
$scope.reloadList();
} else{
alert(response.message);
$scope.reloadList();
}
}
)
}
//模糊查询
$scope.searchEntity={};
$scope.search = function(page,rows){
brandService.search(page,rows,$scope.searchEntity).success(
function (response) {
$scope.list = response.rows;
$scope.paginationConf.totalItems = response.total;
}
)
}
})
标签:分层 数组 创建 mamicode 信息 dex asc 收购 update
原文地址:https://www.cnblogs.com/wycBolg/p/11854051.html