gpt4 book ai didi

javascript - 如何过滤我的数据? (ng-网格)

转载 作者:行者123 更新时间:2023-12-03 00:58:44 25 4
gpt4 key购买 nike

我认为这很可能非常简单,但我找不到任何关于如何在其网站上显示的“filterText”之外添加过滤器的明确文档。我想做的事情就这么简单:

$scope.filterOptions = {
filter: $scope.myFilter, // <- How to do something like this?
useExternalFilter: true
}

$scope.gridOptions = {
data: 'entries',
enableColumnResize: false,
multiSelect: false,
enableSorting: false,
selectedItems: $scope.selectedEntries,
filterOptions: $scope.filterOptions
}

$scope.lowerLimit = 50;
// My Filter
$scope.myFilter = function(entry) {
if (entry < $scope.lowerLimit) {
return false;
}
return true;
}

编辑:或者也许我可以以某种方式过滤数据源?我试过这个:

$scope.gridOptions = {
data: 'entries | filter: myFilter',
enableColumnResize: false,
multiSelect: false,
enableSorting: false,
selectedItems: $scope.selectedEntries,
}

但是它抛出了很多错误。

最佳答案

您可以使用 Angular 绑定(bind)到 filterOptions.filterText多变的。这里有一个笨蛋来演示:http://plnkr.co/edit/PHdBhF?p=preview

我将在下面发布相同的代码:

    // main.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.filterOptions = {
filterText: ''
};

$scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];

$scope.gridOptions = {
data: 'myData',
filterOptions: $scope.filterOptions
};
});

上面的内容应该与文档页面上的插件大致相同。

    <!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Custom Plunker</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body ng-controller="MyCtrl">
<strong>Filter:</strong><input type="text" ng-model="filterOptions.filterText" />
<br/>
<br/>
<div class="gridStyle" ng-grid="gridOptions"></div>
</body>
</html>

通知ng-model="filterOptions.filterText"关于<input ...> 。这就是所需要的!

关于javascript - 如何过滤我的数据? (ng-网格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com