从服务接收信息后动态构建表
Dynamically build table after it recieves information from service
HTML 代码:
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="color in colors">
<td>{{ color.one }}</td>
<td>{{ color.two }}</td>
<td>{{ color.three }}</td>
</tr>
</tbody>
</table>
控制器:
var SomeController = function ($scope, SomeService, $window) {
var colors= [];
SomeService.someFunction().success(function (data, status, header, config) {
colors= data;
}).error(function (data, status, headers, config) {
// handle error
});
};
基本上,我需要根据后端中的任何内容动态创建我的表......但是,问题是,一旦我调用页面,它就会自动加载列,大约一秒钟后,它将从服务中返回。无论如何,我可以延迟加载时间或让表"刷新"本身以显示新数据。
听起来您可以使用ngShow并等待您的数据在$scope.colors
上解析 这应该会延迟显示您的表,直到调用完成。请尝试以下操作...
<table
class="table table-bordered table-striped"
ng-show="colors" class="ng-hide">
<thead>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="color in colors">
<td>{{ color.one }}</td>
<td>{{ color.two }}</td>
<td>{{ color.three }}</td>
</tr>
</tbody>
</table>
SomeService.someFunction().success(function (data, status, header, config) {
$scope.colors = data; // let colors be defined on $scope
})
相关文章:
- 动态构建一个数据表与scriplets
- Microsoft城域网,动态构建
- 如何将动态构建的字符串作为http头在http.call中与流星一起传递
- 从Javascript动态构建JSON对象列表
- 如果标记是使用 JavaScript 动态构建的,Schema.org 标记是否有效?
- 动态构建2D阵列Javascript
- SlickGrid根据日期错误动态构建列
- 如何动态构建表
- 如何动态构建img标记
- jQuery:从带有 for 循环的数组动态构建表单
- 从 json 动态构建 dom 树
- 加载商店数据以动态构建表单 煎茶触摸2.
- 动态构建 json 对象
- 使用动态构建的 jQuery 承诺链按顺序激活特定元素
- JS/jQuery遍历HTML元素以动态构建字符串
- 有没有办法避免角加载动态构建页面时的抖动效应
- 使用 JavaScript 动态构建 asp:chart
- 动态构建表单
- AngularJS ng-repeat列表是动态构建的,$index始终为零
- Ember.js - 使用输入值动态构建链接