angularjs使用http服务请求网络数据展示

<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/angular.min.js"></script>
<style>
table,
th,
td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
</style>
</head>


<body>
<div ng-app="mapp" ng-controller="mctr">
请输入搜索内容:<input type="text" ng-model="querykey" /><br />
<input type="button" value="批量删除" ng-click="plDelete()" /><input type="button" value="反选" ng-click="fan()"><input type="button" value="增加" ng-click="showd=!showd" />
<br />
<select ng-model="orderKey">
<option value="">--排序--</option>
<option value="id">编号</option>
<option value="price">价格</option>
</select>


<!--添加域-->
<div align="center" ng-show="showd">
<br /> 商品编号:
<input type="text" ng-model="tid" /><br /> 商品名称:
<input type="text" ng-model="tname" /><br /> 商品价格:
<input type="text" ng-model="tprice" /><br /> 商品数量:
<input type="text" ng-model="tnumber" /><br />
<!--二级联动-->
商品产地:
<select ng-options="p.pro for p in pros" ng-model="selectd" ng-change="proChange(selectd)">
<option value="">--选择省--</option>
</select>
<select ng-options="c for c in city" ng-model="citySelectd">
<option value="">--选择市--</option>
</select>
<br /> 新成:
<select ng-model="xcSelect">
<option value="">--请选择--</option>
<option value="新茶">新茶</option>
<option value="成茶">成茶</option>
</select>
<br />
<input type="button" value="添加商品" ng-click="addGoods()" />
<br/><br/>
</div>


<table>
<tr>
<th><input type="checkbox" ng-model="all" ng-click="checkAll()"></th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>产地</th>
<th>新成</th>
<th>操作</th>
</tr>
<tr ng-repeat="t in tea  | filter:querykey| orderBy:orderKey " style="{{$odd?'background-color: red':'background-color: yellow'}}">
<td><input type="checkbox" ng-model="t.ck"></td>
<td>{{t.id}}</td>
<td>{{t.name}}</td>
<td>{{t.price | currency:'¥'}}</td>
<td>{{t.number}}</td>
<td>{{t.chandi}}</td>
<td>{{t.xc}}</td>
<td>
<input type="button" value="修改" ng-click="showUpdate($index)">
<input type="button" value="删除" ng-click="deleteById($index)">
</td>
</tr>
</table>
<!--修改域-->
<div align="center" ng-show="updatePage">
<br /> 商品编号:
<input type="text" ng-model="uid" /><br /> 商品名称:
<input type="text" ng-model="uname" /><br /> 商品价格:
<input type="text" ng-model="uprice" /><br /> 商品数量:
<input type="text" ng-model="unumber" /><br /> 产地:
<input type="text" ng-model="uchandi" /><br /> 新成:
<select ng-model="uXc">
<option value="">--请选择--</option>
<option value="新茶">新茶</option>
<option value="成茶">成茶</option>
</select>
<br />
<input type="button" value="修改商品" ng-click="updateGoods()" />
<br/><br/>
</div>
</div>
<script>
angular.module('mapp', []).controller('mctr', function($scope, $http) {
$http.get('http://result.eolinker.com/rR1VBtT56a6bb220c10b3d44b65b4787a8aec03c4ec32ce?uri=ThirdTest').then(function(response) {
$scope.tea = response.data;
});


// $scope.showd=false;
$scope.tid = "";
$scope.tname = "";
$scope.tprice = "";
$scope.tnumber = "";


$scope.pros = [{
pro: "北京",
childer: ["西二旗", "上地"]
},
{
pro: "河北",
childer: ["邯郸", "石家庄", "保定"]
},
{
pro: "河南",
childer: ["信阳", "南阳", "濮阳"]
},
{
pro: "湖南",
childer: ["长沙", "湘潭庄", "衡阳"]
},
{
pro: "湖北",
childer: ["仙桃", "武汉", "黄石"]
}
];
//添加商品
$scope.addGoods = function() {
var goods = {};
goods.id = $scope.tid;
goods.name = $scope.tname;
goods.price = $scope.tprice;
goods.number = $scope.tnumber;
goods.chandi = $scope.selectd.pro + $scope.citySelectd;
goods.xc = $scope.xcSelect;
$scope.tea.push(goods);
$scope.showd = false;
}


//删除根据表格index
$scope.deleteById = function(id) {
$scope.tea.splice(id, 1);
}
//修改----------
//显示修改域
$scope.updatePage = false;
$scope.showUpdate = function(id) {
$scope.updatePage = true;
$scope.utea = $scope.tea[id];
$scope.uid = $scope.tea[id].id;
$scope.uname = $scope.tea[id].name;
$scope.uprice = $scope.tea[id].price;
$scope.unumber = $scope.tea[id].number;
$scope.uchandi = $scope.tea[id].chandi;
$scope.uXc = $scope.tea[id].xc;


}
//提交修改信息,完成修改
$scope.updateGoods = function() {
$scope.utea.id = $scope.uid;
$scope.utea.name = $scope.uname;
$scope.utea.price = $scope.uprice;
$scope.utea.number = $scope.unumber;
$scope.utea.chandi = $scope.uchandi;
$scope.utea.xc = $scope.uXc;
$scope.updatePage = false;
}
//批量删除
$scope.plDelete = function() {
for(var i = 0; i < $scope.tea.length; i++) {
if($scope.tea[i].ck) {
$scope.tea.splice(i, 1);
i--;
}
}
}
//全选
$scope.checkAll = function() {
for(var i = 0; i < $scope.tea.length; i++) {
$scope.tea[i].ck = $scope.all;
}


}
//反选
$scope.fan = function() {
for(var i = 0; i < $scope.tea.length; i++) {
$scope.tea[i].ck = !$scope.tea[i].ck;
}
}
//二级联动
// $scope.selectd = $scope.pros[0];
// $scope.city = $scope.pros[0].childer;
//省改变,市跟着变
$scope.proChange = function(selectd) {
$scope.city = $scope.selectd.childer;
}
});
</script>
</body>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值