动态列表和Ng重复

时间:2015-07-03 13:40:33

标签: html angularjs asp.net-web-api

我转动了一张桌子并通过webapi angurlarjs将其返回到controller controller。根据返回的方式,列标题是动态的。

问题:如何使用ng-repeattable

显示它

网络API:

 [System.Web.Http.HttpGet]
        public IEnumerable<dynamic> GetPayrollSampleList(int payrollId)
        {
                int schoolId = Convert.ToInt32(UserDataPieces(2));
                int schoolBranchId = Convert.ToInt32(UserDataPieces(5));

                DataTable dt = new DataTable();
                dt = unitOfWork.FinanceRepository.GetPayrollSampleList(payrollId, schoolBranchId, schoolId);

                        foreach (DataRow row in dt.Rows)
                        {
                            ExpandoObject dynamicDto = new ExpandoObject();

                            foreach (DataColumn column in dt.Columns)
                            {
                                ((IDictionary<String, Object>)dynamicDto).Add(column.ColumnName, row[column.ColumnName]);
                            }

                            yield return dynamicDto;
                        }
        }

angularjs:

 $scope.loadGrid = function (payrollId) {
        dataService.getItems(baseAddress + '/GetPayrollSampleList', { payrollId: payrollId })
                .success(function (data) {
                    $scope.myData = data;
            })
                .error(function () {
                    toastr.error("Error loading payroll");
            });
    };

UI:

enter image description here

1 个答案:

答案 0 :(得分:0)

所以你有$ scope.myData成功撤回了2d数组,第一行是标题?工作小提琴http://jsfiddle.net/joshuaohana/1nhcf4g6/1/

<table>
  <tr ng-class='{header:$first}' ng-repeat="row in myData">
    <td ng-repeat="column in row">
      {{column}}
    </td>
  </tr>
</table>