Javascript 筛选数组记录
.js .htmlJavascript 筛选数组记录,javascript,angularjs,Javascript,Angularjs,.js .html wordName: nameWeightpct: 我需要的是,我想搜索“wordName”是“Word”还是“WO”的记录。“nameWeightpct”是40。就像mysql中的“like%”查询一样。但现在我只想在前端做。我有一个webservice,它有所有记录,但我想筛选一个数组,该数组的记录与输入的值完全相同或相似。您可以创建两个变量来接受“wordName”和“nameWeightpct”的搜索值,并使用Angular提供的筛选器 下面是一个示例代码: &
wordName:
nameWeightpct:
我需要的是,我想搜索“wordName”是“Word”还是“WO”的记录。“nameWeightpct”是40。就像mysql中的“like%”查询一样。但现在我只想在前端做。我有一个webservice,它有所有记录,但我想筛选一个数组,该数组的记录与输入的值完全相同或相似。您可以创建两个变量来接受“wordName”和“nameWeightpct”的搜索值,并使用Angular提供的筛选器 下面是一个示例代码:
<strong><font color="#660099" face="Arial" size="1">wordName : </font></strong>
<strong><font color="#660099" face="Arial" size="1"><input name="wordName" type="text" value=""></font></strong>
<strong><font color="#660099" face="Arial" size="1">nameWeightpct : </font></strong>
<strong><font color="#660099" face="Arial" size="1"><input name="nameWeightpct" type="text" value=""></font></strong>
搜索名称:
搜索电话:
电话
{{friend.name}
{{朋友.电话}
您需要在数据上循环,然后自己实现这样的功能。很简单。你尝试过什么,但什么不起作用?
<strong><font color="#660099" face="Arial" size="1">wordName : </font></strong>
<strong><font color="#660099" face="Arial" size="1"><input name="wordName" type="text" value=""></font></strong>
<strong><font color="#660099" face="Arial" size="1">nameWeightpct : </font></strong>
<strong><font color="#660099" face="Arial" size="1"><input name="nameWeightpct" type="text" value=""></font></strong>
<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}]"></div>
<label>Search Name: <input ng-model="searchName"></label>
<label>Search Phone: <input ng-model="searchPhone"></label>
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchName | filter: searchPhone">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>