的.js
"rpsCommonWord": [
{
"addressWeightPct": "60",
"charSubstituteWeightPct": "15",
"nameWeightPct": "40",
"oIdNumber": "21",
"shortWordMinLthWeightPct": "100",
"substituteWeightPct": "5",
"wordName": "Word 3"
},
{
"addressWeightPct": "60",
"charSubstituteWeightPct": "15",
"nameWeightPct": "40",
"oIdNumber": "21",
"shortWordMinLthWeightPct": "100",
"substituteWeightPct": "5",
"wordName": "abc 3"
},
{
"addressWeightPct": "60",
"charSubstituteWeightPct": "15",
"nameWeightPct": "50",
"oIdNumber": "21",
"shortWordMinLthWeightPct": "100",
"substituteWeightPct": `enter code here`"5",
"wordName": "Wordefd 3"
}
];
$scope.onClickGo = function() {
//
};
html的
<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>
我需要的是,我想搜索&#34; wordName&#34;是&#34; Word&#34;或&#34; WO&#34;。和#34; nameWeightpct&#34;是40,就像&#34;喜欢%&#34;在mysql中查询。但是现在我只想在前端做这件事。我有webservice,其中包含所有记录,但我想过滤具有与输入值完全相似的记录的数组。
答案 0 :(得分:2)
您可以创建两个变量来接受“wordName”和“nameWeightpct”的搜索值,并使用Angular提供的过滤器。
以下是示例代码:
<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>