<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.js" ></script>
<style>
.redColor{ color:red; }
</style>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.goods=[{"id":80,"name":"iphone","price":5400},
{"id":1200,"name":"ipad mini","price":2200},
{"id":500,"name":"ipad air","price":2340},
{"id":29,"name":"ipad","price":1420},
{"id":910,"name":"imac","price":15400}];
$scope.orderColumn="name";
$scope.orderSign="-";
$scope.sortProduct=function(sortColumn){
$scope.orderColumn=sortColumn;
if($scope.orderSign=="-"){
$scope.orderSign="";
}else{
$scope.orderSign="-";
}
}
$scope.remove = function(name) {
if(confirm("确定要清空"+name+"吗")) {
var p;
for(index in $scope.goods ){
p=$scope.goods[index];
if(p.name==name){
$scope.goods.splice(index,1);
}
}
}
}
$scope.removeAll = function() {
if(confirm("你确定套清空购物车所有商品吗?")) {
$scope.goods = [];
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-model="search" placeholder="产品名称"/>
<button ng-click="removeAll()">全部删除</button>
<table border="1"cellspacing="0">
<tr>
<td>产品编号<button ng-click="sortProduct('id')">^</button></td>
<td>产品名称<button ng-click="sortProduct('name')">^</button></td>
<td>产品价格<button ng-click="sortProduct('price')">^</button></td>
<td><a>删除</a></td>
</tr>
<tr ng-repeat="x in goods | filter:{'name':search}|orderBy:(orderSign + orderColumn)">
<td>{{x.id }}</td>
<td>{{x.name}}</td>
<td>{{x.price |currency :"(RMB)"}}</td>
<td ng-click="remove(x.name)"><a>删除</a></td>
</tr>
</table>
</body>
</html>
An_form排序
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- This chapter covers Effects with jQuery jQuery's utility ...
- “上一辈创业者必须有资金才能够开始创业,但今天的创业者只要能够抓住一个创业亮点,就可以获得全世界的投资。” ...