angularJs基础学习
实例化一个angularJs模块
<body class="hold-transition skin-red sidebar-mini" ng-app="app" ng-controller="brandController" >
<!-- .box-body -->
<div class="box-header with-border">
<h3 class="box-title">品牌管理</h3>
</div> <div class="box-body"> <!-- 数据表格 -->
<div class="table-box"> <!--工具栏-->
<div class="pull-left">
<div class="form-group form-inline">
<div class="btn-group">
<button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ng-click="entity={}" ><i class="fa fa-file-o"></i> 新建</button>
<button type="button" class="btn btn-default" title="删除" ng-click="dele()"><i class="fa fa-trash-o" ></i> 删除</button>
<button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
</div>
</div>
</div>
<div class="box-tools pull-right">
<div class="has-feedback">
品牌名称:<input ng-model="searchEntity.name"> 品牌首字母:<input ng-model="searchEntity.firstChar">
<button class="btn btn-default" ng-click="reloadList()">查询</button>
</div>
</div>
<!--工具栏/--> <!--数据列表-->
<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right:0px">
<input id="selall" type="checkbox" class="icheckbox_square-blue">
</th>
<th class="sorting_asc">品牌ID</th>
<th class="sorting">品牌名称</th>
<th class="sorting">品牌首字母</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="entity in list">
<td><input type="checkbox" ng-click="updateSelection($event, entity.id)" ></td>
<td>{{entity.id}}</td>
<td>{{entity.name}}</td>
<td>{{entity.firstChar}}</td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" ng-click="findOne(entity.id)" >修改</button>
</td>
</tr> </tbody>
</table>
<!--数据列表/-->
<tm-pagination conf="paginationConf"></tm-pagination> </div>
<!-- 数据表格 /--> </div>
<!-- /.box-body --> <!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">品牌编辑</h3>
</div>
<div class="modal-body">
<table class="table table-bordered table-striped" width="800px">
<tr>
<td>品牌名称</td>
<td><input class="form-control" placeholder="品牌名称" ng-model="entity.name"> </td>
</tr>
<tr>
<td>首字母</td>
<td><input class="form-control" placeholder="首字母" ng-model="entity.firstChar"> </td>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" ng-click="save()">保存</button>
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
</div>
</div>
</div> </body>
</html>
<script type="text/javascript">
var app=angular.module('app',['pagination']);
app.controller('brandController',function($scope,$http){
//查询品牌列表
$scope.findAll=function(){
$http.get('../brand/findAll.do').success(
function(response){
$scope.list=response;
}
);
}
//分页控件配置currentPage:当前页 totalItems :总记录数 itemsPerPage:每页记录数 perPageOptions :分页选项 onChange:当页码变更后自动触发的方法
$scope.paginationConf = {
currentPage: ,
totalItems: ,
itemsPerPage: ,
perPageOptions: [, , , , ],
onChange: function(){
$scope.reloadList();
}
};
//刷新列表
$scope.reloadList=function(){
$scope.search( $scope.paginationConf.currentPage , $scope.paginationConf.itemsPerPage );
}
//分页
$scope.findPage=function(page,size){
$http.get('../brand/findPage.do?page='+page +'&size='+size).success(
function(response){
$scope.list=response.rows;//显示当前页数据
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
//新增
$scope.save=function(){
var methodName='add';//方法名
if($scope.entity.id!=null){
methodName='update';
}
$http.post('../brand/'+methodName +'.do',$scope.entity).success(
function(response){
if(response.success){
$scope.reloadList();//刷新
}else{
alert(response.message);
}
}
);
}
//查询实体
$scope.findOne=function(id){
$http.get('../brand/findOne.do?id='+id).success(
function(response){
$scope.entity=response;
}
);
}
$scope.selectIds=[];//用户勾选的ID集合
//用户勾选复选框
$scope.updateSelection=function($event,id){
if($event.target.checked){
$scope.selectIds.push(id);//push向集合添加元素
}else{
var index= $scope.selectIds.indexOf(id);//查找值的 位置
$scope.selectIds.splice(index,);//参数1:移除的位置 参数2:移除的个数
}
}
//删除
$scope.dele=function(){
if(confirm('确定要删除吗?')){
$http.get('../brand/delete.do?ids='+$scope.selectIds).success(
function(response){
if(response.success){
$scope.reloadList();//刷新
}else{
alert(response.message);
}
}
);
}
}
$scope.searchEntity={};
//条件查询
$scope.search=function(page,size){
$http.post('../brand/search.do?page='+page +'&size='+size, $scope.searchEntity).success(
function(response){
$scope.list=response.rows;//显示当前页数据
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
});
</script>
定义ng-app模块,代表相关模块由angularJs来接管,定义一个控制层,来控制相关逻辑
angularJs基础学习的更多相关文章
- AngularJS基础入门初探
一.AngularJS简介 1.1 什么是AngularJS (1)一款非常优秀的前端JS框架,可以方便实现MVC/MVVM模式 (2)由Misko Hevery 等人创建,2009年被Google所 ...
- salesforce 零基础学习(五十二)Trigger使用篇(二)
第十七篇的Trigger用法为通过Handler方式实现Trigger的封装,此种好处是一个Handler对应一个sObject,使本该在Trigger中写的代码分到Handler中,代码更加清晰. ...
- 如何从零基础学习VR
转载请声明转载地址:http://www.cnblogs.com/Rodolfo/,违者必究. 近期很多搞技术的朋友问我,如何步入VR的圈子?如何从零基础系统性的学习VR技术? 本人将于2017年1月 ...
- IOS基础学习-2: UIButton
IOS基础学习-2: UIButton UIButton是一个标准的UIControl控件,UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedContro ...
- HTML5零基础学习Web前端需要知道哪些?
HTML零基础学习Web前端网页制作,首先是要掌握一些常用标签的使用和他们的各个属性,常用的标签我总结了一下有以下这些: html:页面的根元素. head:页面的头部标签,是所有头部元素的容器. b ...
- python入门到精通[三]:基础学习(2)
摘要:Python基础学习:列表.元组.字典.函数.序列化.正则.模块. 上一节学习了字符串.流程控制.文件及目录操作,这节介绍下列表.元组.字典.函数.序列化.正则.模块. 1.列表 python中 ...
- python入门到精通[二]:基础学习(1)
摘要:Python基础学习: 注释.字符串操作.用户交互.流程控制.导入模块.文件操作.目录操作. 上一节讲了分别在windows下和linux下的环境配置,这节以linux为例学习基本语法.代码部分 ...
- CSS零基础学习笔记.
酸菜记 之 CSS的零基础. 这篇是我自己从零基础学习CSS的笔记加理解总结归纳的,如有不对的地方,请留言指教, 学前了解: CSS中字母是不分大小写的; CSS文件可以使用在各种程序文件中(如:PH ...
- Yaf零基础学习总结5-Yaf类的自动加载
Yaf零基础学习总结5-Yaf类的自动加载 框架的一个重要功能就是类的自动加载了,在第一个demo的时候我们就约定自己的项目的目录结构,框架就基于这个目录结构来自动加载需要的类文件. Yaf在自启动的 ...
随机推荐
- 第三章 深入分析Java Web的中文乱码问题(待续)
几种常见的编码格式 在Java中需要编码的场景 在Java中如何编解码 在Java Web中涉及的编解码 在JS中的编码问题 常见问题分析 一种繁简转换的实现方式
- python 继承进阶
继承进阶 面向对象 1.类:具有相同属性和方法 的一类事物 类名可以实例化一个对象 类名可以调用类属性,(静态属性 和(方法)动态属性) 2.对象:也就是实例 对象名:调用对象属性 调用方法 3 ...
- Python之函数目录(自定义函数,内置函数,装饰器,迭代器,生成器)
1.初始函数 2.函数嵌套及作用域 3.装饰器 4.迭代器和生成器 6.内置函数 7.递归函数 8.匿名函数 9.函数相关定义 10.三元表达式.列表推导式.生成器表达式 11.函数与方法的区别
- 用UltraISO把硬盘文件制作成ISO格式
转自:https://wenku.baidu.com/view/0052c88dcc22bcd126ff0cbf.html 用UltraISO把硬盘文件制作成ISO格式方法: 制作硬盘ISO文件步骤一 ...
- java线程的三种实现方式
线程实现的三种种方式: 一个是继承Thread类,实现run()方法: 一个是实现Runnable接口,实现run()方法: 一个是实现Callable接口,实现call()方法:该方式和实现Runn ...
- PCL—点云分割(最小割算法) 低层次点云处理
1.点云分割的精度 在之前的两个章节里介绍了基于采样一致的点云分割和基于临近搜索的点云分割算法.基于采样一致的点云分割算法显然是意识流的,它只能割出大概的点云(可能是杯子的一部分,但杯把儿肯定没分割出 ...
- Log4Net 调试时输出sql到 视图->输出的sql语句
1.log4net.xml <?xml version="1.0" encoding="utf-8" ?> <!--log4net 配置--& ...
- String的字符串相加是怎么实现的?
http://bbs.csdn.net/topics/60485130 首先看 String str = "a" + "b" + "c"; ...
- STL之priority_queue(优先队列)
priority_queue是一个容器适配器,在这个容器里第一个数据元素是最大的.它的使用场景是什么样:如果12306抢票,为什么黄牛能抢这么多票,感觉12306那边的请求队列是一个优先队列,黄牛的请 ...
- sequoiadb的c++应用开发1
使用sequoiadb开发c++应用时需要使用BSON对象,本篇主要讲下BSON的操作方面的东西 1:构建一个_id的BSON对象 BSON的c++驱动给我提供了一个宏BSON,使用该对象可以很方便的 ...