我通過webapi controller
將錶轉回到我的angurlarjs
controller
。根據返回的方式,列標題是動態的。動態列表和Ng-Repeat
問題:如何使用ng-repeat
和table
來顯示它?
Web的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:
你先寫了代碼嗎? – Vineet
@Vineet我已經將代碼寫入了angularjs。 – uikrosoft
數據的對象是什麼?你能舉一個例子嗎? –