Angular js仅在一列中过滤精确匹配搜索 [英] Angular js filter exact match search in only one column
本文介绍了Angular js仅在一列中过滤精确匹配搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何仅针对一列实现完全匹配搜索过滤器,其余部分不应完全匹配。
假设我有一个员工表,其中包含员工姓名和其他详情。我想在完全匹配时过滤名称,但我想留下其余部分。
我如何以简单的方式做到这一点?
我的尝试:
HTML:
How do i implement exact match search filter for only one column and rest should not be exact match.
Let say i have a employee table with employee name and other details. I would like to filter name when its matched exactly but i want to leave the rest.
How do i do it in simple way?
What I have tried:
HTML:
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
table {
border-style: solid;
border-collapse:collapse;
}
th {
border-style: solid;
}
td {
border-style: solid;
}
</style>
</head>
<body ng-app="mymodule">
<div ng-controller="myController">
<table>
<thead>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Salary</th>
<th>City</th>
</tr>
<tr>
<th><input type="text" ng-model="searchText.name" /></th>
<th><input type="text" ng-model="searchText.gender" /></th>
<th><input type="text" ng-model="searchText.salary" /></th>
<th><input type="text" ng-model="searchText.city" /></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees | filter:searchText">
<td> {{ employee.name }} </td>
<td> {{ employee.gender }} </td>
<td> {{ employee.salary }} </td>
<td> {{ employee.city }} </td>
</tr>
</tbody>
</table>
</div>
</body>
<script src="Scripts/angular.min.js"></script>
<script src="JavaScript.js"></script>
</html>
Angular:
Angular:
var app = angular.module("mymodule", []);
app.controller("myController", function ($scope) {
var employees = [
{ name: "Ben", gender: "Male", salary: 55000, city: "London" },
{ name: "Sara", gender: "Female", salary: 68000, city: "Newyork" },
{ name: "Mark", gender: "Male", salary: 57000, city: "Ashland" },
{ name: "Pam", gender: "Female", salary: 53000, city: "Hongkong" },
{ name: "Todd", gender: "Male", salary: 60000, city: "London" },];
$scope.employees = employees;
$scope.flag = function () {
if ($searchText.name === employees.name) {
return true;
}
}
});
推荐答案
范围){
var employees = [
{name:Ben,性别:男,工资:55000,城市: London},
{姓名:Sara,性别:女性,工资:68000,城市:Newyork},
{姓名:Mark,性别:男性,薪水:57000,城市:Ashland},
{姓名:Pam,性别:女性,工资:53000,城市:香港},
{姓名:Todd,性别:男性,工资:60000,城市:伦敦} ,];
scope) { var employees = [ { name: "Ben", gender: "Male", salary: 55000, city: "London" }, { name: "Sara", gender: "Female", salary: 68000, city: "Newyork" }, { name: "Mark", gender: "Male", salary: 57000, city: "Ashland" }, { name: "Pam", gender: "Female", salary: 53000, city: "Hongkong" }, { name: "Todd", gender: "Male", salary: 60000, city: "London" },];
scope.employees = employees;
scope.employees = employees;
scope.flag = function(){
if(
scope.flag = function () { if (
这篇关于Angular js仅在一列中过滤精确匹配搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文