Yas*_*een 5 javascript angularjs smart-table
我有一种情况,我正在使用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>
Run Code Online (Sandbox Code Playgroud)
我正在测试2种不同的情况。
在我的控制器中,我首先调用相同的函数,但发送虚拟数组,在第二种情况下,我发送从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);
});
Run Code Online (Sandbox Code Playgroud)
当我使用case1时,排序工作正常。但是,当我使用case2时,排序不起作用。单击它,数据就消失了。我尝试调试以查看是否在单击过滤器时再次调用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);
});
Run Code Online (Sandbox Code Playgroud)
然后在 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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1738 次 |
最近记录: |