0

使用下面的代码(控制器和html页面),我看到表格没问题。但是过滤器不起作用。当我在过滤器中输入内容时:

  1. 所有数据消失(即使过滤器与某些记录匹配)
  2. 当我清洁过滤器时不会回来

任何想法 ?

谢谢,

angular.module('myApp').controller('customerListController', ['$scope', '$http', '$location', function ($scope, $http, $location) {

    getCustomers = function () {
        var url = '......';

        $http({ method: 'GET', url: url })
        .success(function (data, status, headers, config) {
            $scope.customers = data.Customers;
        })
        .error(function (data, status, headers, config) {
        });

    };

    $scope.customers = getCustomers();

}]);

<table st-table="customers" st-safe-src="rowCollection" class="table table-striped">
    <thead>
        <tr>
            <th st-sort="FirstName">FirstName</th>
            <th st-sort="LastName">LastName</th>
            <th st-sort="Code">Code</th>
            <th st-sort="Email">Email</th>
        </tr>
        <tr>
            <th colspan="4"><input st-search="" class="form-control" placeholder="global search ..." type="text" /></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in customers">
            <td>{{row.FirstName}}</td>
            <td>{{row.LastName}}</td>
            <td>{{row.Code}}</td>
            <td>{{row.Email}}</td>
        </tr>
    </tbody>
</table>

更新 1:我添加了下面的代码,但现在更改了。

$scope.customers = getCustomers();
$scope.rowCollection = $scope.customers;
4

2 回答 2

0

不知道你是否还在寻找答案。通过这样做,$scope.rowCollection = $scope.customers;您可以保留对$scope.customers.

如果我是对的,您必须通过执行以下操作来复制您的客户数据:

var yourCustomersData = getCustomers();
$scope.customers = angular.copy(yourCustomersData); // st-table
$scope.rowCollection = angular.copy(yourCustomersData); // st-safe-src

我认为它会像那样工作。

于 2015-09-18T12:02:23.113 回答
0

您只是混淆了什么是 st-table 和 st-safe-src ,当您进行搜索或过滤数据网格时,st-table 是临时数据智能表过滤来自 st-safe-src 的主要数据,然后分配给st-table临时数据源

在这里,您不想将数据单独分配给 st-table,因为它是一个可选的,最初是智能表查找它并过滤数据然后分配给它。

在您的代码中,我只是更改了这一行:

在你的 Js 中,我看到了一些奇怪的东西。您的代码:

$scope.customers = getCustomers();

在这里,您将不可返回的函数分配给您的数据源。因此,您的数据源可能未定义。所以我只改变那一行。

getCustomers();

在您的 HTML 中:

<table st-table="tempCollection" st-safe-src="customers" class="table table-striped">

在您的 Js 代码中:

    angular.module('myApp').controller('customerListController', ['$scope', '$http', '$location', function ($scope, $http, $location) {

    getCustomers = function () {
        var url = '......';

        $http({ method: 'GET', url: url })
        .success(function (data, status, headers, config) {
            $scope.customers = data.Customers; // st-safe-src
            //no need to assign st-table
        })
        .error(function (data, status, headers, config) {
        });

    };

    getCustomers();

}]);
于 2020-12-19T06:13:25.200 回答