2016-10-02 49 views
-1

我創建了一個列:表名,日期,性別和薪水。桌子上方有兩個搜索文本框。 1)按名稱搜索2)按工資搜索。那麼我已經給出了一個名爲「精確匹配」的複選框。 每當我在'按名稱搜索'文本框中鍵入任何字母,並且如果該字母出現在表的名稱列中,則頁面將返回這些行。工資文本框也會發生同樣的情況。但是,當我選中精確匹配框後,只有在確切值匹配時纔會返回。例如,如果我在名稱搜索框中輸入「Ben」,並且如果Ben存在於名稱列中,則只有它會返回該特定行,否則不會。通過角JS執行完全匹配

這裏的問題是與字母完全匹配工作正常,但是當我使用工資欄的精確匹配並鍵入任何數字時,它不會返回任何值。同樣的事情也發生在日期。我不確定在處理數字時我們需要在代碼中添加一些內容。

下面是HTML代碼:

<!doctype html> 
<html ng-app="myModule"> 
<head> 
<script src="../angular.min.js"> </script> 
<script src="Script12.js"> </script> 
</head> 
<body> 
<div ng-controller="myController"> 
<input type="text" placeholder="search name" ng-model="searchText.name"> 
<input type="text" placeholder="search gender" ng-model="searchText.gender"> 
<input type="text" placeholder="search DOB" ng-model="searchText.dateOfBirth"> 
<input type="text" placeholder="search Salary" ng-model="searchText.salary"> 
<input type="checkbox" ng-model="exactMatch">EXACT MATCH 

<br><br> 
<table> 
<thead> 
<tr> 
<th>Name</th> 
<th>Date Of Birth</th> 
<th>Gender</th> 
<th>Salary</th> 
</tr> 
</thead> 
<tbody> 
<tr ng-repeat="employee in employees |filter:searchText:exactMatch "> 
<td> {{employee.name}}</td> 
<td> {{employee.dateOfBirth | date:"MM/dd/yyyy"}}</td> 
<td> {{employee.gender}}</td> 
<td> {{employee.salary}}</td> 
</tr> 


</tbody> 
</table> 

</div> 
</body> 

</html> 

Java腳本文件:

/// <reference path="../angular.min.js" /> 

var myApp = angular.module("myModule",[]); 

myApp.controller("myController", function($scope) { 

    var employees = [ 
    {name: "Ben", dateOfBirth: new Date("November 20, 1989"), gender: "Male", salary:50000 }, 
    {name: "Stifler", dateOfBirth: new Date("July 15, 19002"), gender: "Female", salary:700000 }, 
    {name: "Gordon", dateOfBirth: new Date("April 10, 2006"), gender: "Male", salary:900000000 }, 
    {name: "Ramsay", dateOfBirth: new Date("January 18, 1996"), gender: "Male", salary:87864521 }, 
    {name: "Leon", dateOfBirth: new Date("February 8, 2009"), gender: "Female", salary:213265478 } 
    ]; 
    $scope.employees = employees; 


}); 

回答

0

嘗試改變輸入類型薪水場 . 當精確匹配是對角採用嚴格的比較編號, ===而不是==,因此當使用文本字段類型時,類型不匹配。

+0

非常感謝。改變輸入類型真的解決了這個問題。 –