angularJs模糊查询
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>angularFilter</title>
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<script type="text/javascript" src="../js/angular-1.2.22.js" ></script>
<script src="../js/product.js"></script>
</head>
<body ng-app="myApp" ng-controller="productController">
<div class="container">
<form class="navbar-form pull-left">
<input type="text" class="span2" placeholder="Search" ng-model="search.id">
</form>
<table class="table">
<thead>
<tr>
<!--dropup:true 这个class就显示,即升序,否则不显示!-->
<!--注意,这里是ng-class,还有droupup:order中间是没有任何空格的!!!!-->
<th ng-class="{dropup:order ===''}" ng-click="changeOrder('id')">
产品编号<span class="caret"></span>
</th>
<th ng-class="{dropup:order ===''}" ng-click="changeOrder('name')">
产品名称<span class="caret"></span>
</th>
<th ng-class="{dropup:order === ''}" ng-click="changeOrder('price')">
产品价格<span class="caret"></span>
</th>
</tr>
</thead>
<tbody>
<!--<tr ng-repeat="product in products | filter:{id:search}">-->
<!--order+orderType注意这两个字段是有顺序的 不能反着写-->
<tr ng-repeat="product in products | filter:search | orderBy : order+orderType">
<td>
{{product.id}}
</td>
<td>
{{product.name}}
</td>
<td>
{{product.price | currency : "(RMB)"}}
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Js代码
var app = angular.module("myApp",[]);
app.service("products",function(){
return [{
id : 1111,
name : "iphone",
price : 5000
},{
id : 2222,
name : "iphone 4",
price : 1993
},{
id : 1091,
name : "iphone 5",
price : 2893
},{
id : 1792,
name : "iphone 6",
price : 4500
}];
});
app.controller("productController",function($scope,products){
$scope.products = products;//Angular自动注入
//排序条件
$scope.order = "-";//默认是升序,-表示降序
$scope.orderType = "id" ;//以id来排序,不能直接在页面以id这个字段排序
$scope.changeOrder = function(type){
$scope.orderType = type ;
//如果本来是降序,就变为升序,如果是升序,就变为降序
if($scope.order===''){
$scope.order = '-';
}else{
$scope.order = '';
}
}
});
注意:注意标红色的代码,只需过滤器filter:search和input搜索框绑定的ng-model的search.XX就可以,XX表示products(上面绿色部分)的某一属性,即根据该属性来进行过滤!!!
angularJs模糊查询的更多相关文章
- angularjs实现购物车批量删除,filter模糊查询,排序
数据源 $scope.data=[ {num:1234,name:"ipad",price:3400.00,count:10}, {num:1235,name:"ipho ...
- Mybatis框架的模糊查询(多种写法)、删除、添加(四)
学习Mybatis这么多天,那么我给大家分享一下我的学习成果.从最基础的开始配置. 一.创建一个web项目,看一下项目架构 二.说道项目就会想到需要什么jar 三.就是准备大配置链接Orcl数据库 & ...
- js—模糊查询
首先要明白什么是模糊查询(废话又来了),就是根据关键字把列表中符合关键字的一项或某项罗列出来,也就是要检查列表的每一项中是否含有关键字,因此抽象一下就是一个字符串中是否含有某个字符或者字符串. 以下例 ...
- mybatis : trim标签, “等于==”经验, CDATA标签 ,模糊查询CONCAT,LIKE
一.My Batis trim标签有点类似于replace效果. trim 属性, prefix:前缀覆盖并增加其内容 suffix:后缀覆盖并增加其内容 prefixOverrides:前缀判断的条 ...
- combobox实现模糊查询自动填充
利用winform设计软件界面时,经常用到combobox控件,但有时需要绑定数据表中的数据,更进一步,需要实现对数据表中数据的模糊查询功能.本文就讲讲述如何用C#实现combobox下拉列表的模糊查 ...
- [转]ORACLE中Like与Instr模糊查询性能大比拼
instr(title,'手册')>0 相当于 title like '%手册%' instr(title,'手册')=1 相当于 title like '手册%' instr(titl ...
- 关系数据库SQL之基本数据查询:子查询、分组查询、模糊查询
前言 上一篇关系数据库常用SQL语句语法大全主要是关系型数据库大体结构,本文细说一下关系型数据库查询的SQL语法. 语法回顾 SELECT [ALL|DISTINCT] <目标列表达式>[ ...
- StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改
前言 使用StackExchange.Redis没有直接相关的方法进行模糊查询的批量删除和修改操作,虽然可以通过Scan相关的方法进行模糊查询,例如:HashScan("hashkey&qu ...
- SQL SERVER 的模糊查询 LIKE
今天写个动态脚本,需要把数据库里面包含“USER_"的表删除掉,突然想不起来如何搜索通配字符了,赶紧查查MSDN,整理了下模糊查询的知识点,留着以后查阅用. LIKE模糊查询的通配符 通配符 ...
随机推荐
- 学好 Python 的 11 个优秀资源【转载】
Python是目前最流行.最易学最强大的编程语言之一(学习Python的五大理由),无论你是新手还是老鸟,无论是用于机器学习还是web开发(Pinterest就是案例),Python都是一件利器.此外 ...
- 浩瀚技术 安卓版移动开单手持微POS PDA无线移动开单软件 -安卓版移动手持开单设备
PDA数据采集器,是深圳浩瀚技术有限公司最新研发的一款安卓版移动手持开单设备,它通过WIFI和GPRS连接并访问电脑,从进销存软件中读取数据,实现移动开单,打破电脑开单模式. 它自带扫描器,可直接扫描 ...
- AngularJS 包含HTML文件
类似于python tornado的include方法,同样是可以在一个html文件中加载另外一个html文件,这样可以不用重复的写一些几乎不改变的代码. 首先创建两个文件,然后代码如下: <! ...
- 【转】win8.1下安装ubuntu
参考:http://jingyan.baidu.com/article/14bd256e0ca52ebb6d26129c.html Ubuntu 系统是一款优秀的.基于GNU/Linux 的平台的桌面 ...
- http://m.blog.csdn.net/article/details?id=8237698
http://m.blog.csdn.net/article/details?id=8237698
- Python基础5- 运算符
Python的运算符和其他语言的类似,主要有:算术运算符.比较运算符.逻辑运算符.赋值运算符.成员运算符.位运算符 ----------------------------------------算术 ...
- Python学习笔记08
正则表达式包re match,search,sub re.match(pattern, string, flags=0) re.search(pattern, string, flags=0) r ...
- Image Transformation in WPF输入日志标题
Image transformation is a process of rotating and scaling images. Rotating Images There are two ways ...
- The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551
Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- 一个动画 Label (走马观花)
UILabel中一个水平移动的Label UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 300, 300)]; U ...