购物车——(查询,排序)

<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.goods = [{
num: 80,
name: "iphone",
price: 5000
}, {
num: 1200,
name: "ipad mini",
price: 2200
}, {
num: 500,
name: "ipad air",
price: 2340
}, {
num: 29,
name: "ipad",
price: 1420
}, {
num: 910,
name: "imac",
price: 6000
}];
$scope.dele = function(name) {
if(window.confirm("确定要删除" + name + "吗?")) {
for(index in $scope.goods) {
if(name == $scope.goods[index].name) {
$scope.goods.splice(index, 1);
}
}
}
}
$scope.sel = "请选择";
$scope.isPrice = function(price) {
var priceArr = $scope.sel.split("-");
var priceMin = priceArr[0];
var priceMax = priceArr[1];
if($scope.sel == "请选择") {
return true;


} else {
if(isNaN(priceMax)) {
if(price >= priceMin) {
return true;
} else {
return false;
}
} else {
if(price >= priceMin && price <= priceMax) {


return true;
} else {
return false;
}
}
}
}
$scope.flag = "";
$scope.orderColumn = "id";
$scope.order = function(column) {


$scope.orderColumn = column;
if($scope.flag == "") {
$scope.flag = "-";
} else {
$scope.flag = "";
}
}
});
</script>
</head>


<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" placeholder="请输入商品" ng-model="select" />
<select ng-model="sel">
<option>请选择</option>
<option>0-2000</option>
<option>2001-3000</option>
<option> 3001-4000</option>
<option> 4001-5000</option>
<option> 5001-6000</option>
<option> 6001-无限大</option>
</select>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th ng-click="order('num')">商品编号</th>
<th ng-click="order('name')">商品名称</th>
<th ng-click="order('price')">商品价格</th>
<th>操作</th>
</tr>
<tr ng-repeat="g in goods | filter:{name:select} | orderBy:flag+orderColumn" ng-show="isPrice(g.price)">
<td>{{g.num}}</td>
<td>{{g.name}}</td>
<td>{{g.price}}</td>
<td><input type="button" value="删除" ng-click="dele(g.name)" /></td>
</tr>
</table>
</body>


</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值