使用angularJS接收json数据并进行数据的显示

1.引入JS

<script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>

2.指定模块和控制器

<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="brandController" ng-init = findAll()>

3.编写js代码

<script type="text/javascript">
        var app= angular.module('pinyougou',[]);//定义模块
            app.controller('brandController',function($scope,$http){
            //读取列表
            $scope.findAll = function(){
                $http.get('../brand/findAll.do').success(
                        function(response){
                            $scope.list = response;
                        }
                );
            }    
        });
    </script>

4.循环数据表格

<tbody>
    <tr ng-repeat="entity in list">
         <td><input  type="checkbox" ></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"  >修改</button>                                           
          </td>
     </tr>                                     
</tbody>

5.结果显示

猜你喜欢

转载自www.cnblogs.com/itboxue/p/10800416.html