Angularjs智能表不支持动态数据
Angularjs Smart table not working for Dynamic data
我有一个情况,我使用angularJs智能表过滤。
html:<section class="main" ng-init="listAllWorkOrderData()">
<table st-table="listWorkOrderResponse">
<thead>
<tr>
<th st-sort="id">ID <i></i></th>
<th st-sort="project">Project <i></i></th>
</tr>
</thead>
<tbody ng-repeat="workOrder in listWorkOrderResponse">
<tr>
<td>{{workOrder.id}}</td>
<td>{{workOrder.project}}</td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</section>
我正在测试两种不同的病例。
在我的控制器中,我首先调用相同的函数,但发送虚拟数组,在第二种情况下,我发送从api调用收到的数组。
1. Dummy data
$scope.listAllWorkOrderData = function () {
var listWorkOrderResponse = [{"id":"1","project":"project1"},{"id":2,"project":"project2"},{"id":"3","project":"project3"}];
}
2. I am using a service and fetching data through api.
$scope.listAllWorkOrderData = function () {
TestService.listAllWorkOrderData().then(function (response, status, headers, config) {
if (response != undefined && response != null) {
if (!$scope.listWorkOrderResponse) {
$scope.listWorkOrderResponse = [];
}
$scope.listWorkOrderResponse = response;
}, function (response, status, headers, config) {
console.log(response);
});
当我使用case时,排序工作得很好。但是当我使用案例2时,排序不起作用。点击它,数据就消失了。我试着调试,看看当我们点击过滤器时,listAllWorkOrderData函数是否再次被调用。但它只在加载页面填充表时调用一次。这意味着数据出现在listWorkOrderResponse中。那为什么不排序呢?
我通过打印它们来检查两种情况的响应,我发现的唯一区别是来自api调用的listWorkOrderResponse有一个$$hashKey: "object:363"
添加到它。
谁能指出我犯了什么错误?
我可以通过使用stSafeSrc属性来解决这个问题
在控制器中添加
$scope.listAllWorkOrderData = function () {
TestService.listAllWorkOrderData().then(function (response, status, headers, config) {
if (response != undefined && response != null) {
if (!$scope.listWorkOrderResponse) {
$scope.listWorkOrderResponse = [];
}
$scope.listWorkOrderResponse = response;
// we add one more list.
$scope.displayedWOList = [].concat($scope.listWorkOrderResponse);
}, function (response, status, headers, config) {
console.log(response);
});
,然后在html表中添加stSafeSrc属性。
stSafeSrc属性从智能表文档http://lorenzofox3.github.io/smart-table-website/
stSafeSrc属性如果您正在异步引入数据(从远程数据库、restful端点、ajax调用等)必须使用stSafeSrc属性。的集合必须使用单独的集合基本和安全集合,否则可能会导致无限循环。
<section class="main" ng-init="listAllWorkOrderData()">
<table st-table="displayedWOList" st-safe-src="listWorkOrderResponse">
<thead>
<tr>
<th st-sort="id">ID <i></i></th>
<th st-sort="project">Project <i></i></th>
</tr>
</thead>
<tbody ng-repeat="workOrder in displayedWOList">
<tr>
<td>{{workOrder.id}}</td>
<td>{{workOrder.project}}</td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</section>
为什么不工作,我不知道,但你可以通过下面的操作来解决
重复你的回答&创建一个新对象&
var res = [];
for(var i=0; i<response.length; i++) {
var x = {"id":response[i].id, "project":response[i].project};
arr[i] = angular.copy(x);
}
相关文章:
- 如何在没有ajax的情况下将javascript动态数据发送到php变量
- 从要使用Protractor测试的服务器异步加载的动态数据列表的列表
- 不适用于动态数据的Angular指令来自$http
- 如何在字符串中的值之前删除字符串中的动态数据?/ 使用 Lodash 的 _.trimStart 与动态数据
- 剑道数据源,将动态数据发送到服务器
- 无限滚动,动态数据按上次修改状态排序
- 如何在高图表中设置动态数据
- 使用Select2和Meteor.js进行动态数据采集
- 谷歌图表与动态数据和分页是可能的
- 使用AngularJs在自定义TinyMCE编辑器中添加动态数据
- 如何为jQuery帖子输入动态数据参数
- 将不同的符号添加到具有动态数据的高图表中
- Aurelia@儿童动态数据
- 从动态数据生成AngularJS UI模板
- 我可以将初始动态数据从基于RESTful api的服务器端传递到基于角度的前端页面吗
- d3.js带有标签的动态数据
- 将sessionStorage(JSON)中的动态数据附加到Listview中
- 如何使用Javascript在html源中添加动态数据
- 试图在网站上抓取谷歌地图api生成的动态数据,但正常抓取返回空白
- 从angularjs中的$scope在$http.post中发送动态数据