AngularJS table循环数据

<div ng-app="CycleTableApp" ng-controller="CycleTableContrl as vm">
    <h1>类别列表</h1>
    <table class="table">
        <thead>
            <tr>
                <th>类别编号</th>
                <th>类别名称</th>
            </tr>
        </thead>
        <tbody>
            <!--ng-repeat指令,类似foreach循环-->
            <tr ng-repeat="item in vm.firstSortList">
                <td>
                    <p>{{ item.id}}</p>
                </td>
                <td>
                    <p>{{item.displayName}}</p>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<script src="~/Scripts/angular.min.js"></script>
<script>
    var app = angular.module('CycleTableApp', []);
    app.controller('CycleTableContrl', function ($scope,$http) {
        var vm = this;
        vm.getdata = function () {
            $http({
                method: 'POST',
                url: '/AngularjsStudy/GetFirstSort',
                data: {}
            }).then(function successCallback(data) {
                //data有多余属性,data.data才是controller返回的data
                vm.firstSortList = data.data;
            }, function errorCallback(response) {
                // 请求失败执行代码
            });
        }
        vm.getdata();
    });
</script>

Controller

 public ActionResult GetFirstSort()
{
    List<FirstSort> firstSorts = new List<FirstSort>();
    firstSorts.Add(new FirstSort() {id=1,displayName= "绑定分类1" });
    firstSorts.Add(new FirstSort() { id = 2, displayName = "绑定分类2" });
    firstSorts.Add(new FirstSort() { id = 3, displayName = "绑定分类3" });
    firstSorts.Add(new FirstSort() { id = 4, displayName = "绑定分类4" });
    firstSorts.Add(new FirstSort() { id = 5, displayName = "绑定分类5" });
    return Json(firstSorts);
}

实体类

public class FirstSort
{
    public int id { get; set; }
    public string displayName { get; set; }
}

转载于:https://www.cnblogs.com/Lulus/p/7874100.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值