我正在玩AngularJs,并且下面的代码是一个搜索功能。事情是它总是在我输入之前显示整个名单。在我的列表中,我将有超过200个名字(这是一个很长的列表)。我试图实现的目的是在我点击文本框中的第一个字母时显示列表。我怎么能抓住这个? //谢谢
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.min.js"></script>
<div ng-app="">
<div ng-init="friends = [{name:'John'},
{name:'Mary'},
{name:'Mike'},
{name:'Adam'},
{name:'Julie'},
{name:'Juliette'}]"></div>
<span style="color: white">Search:</span> <input ng-model="searchText">
<table style="color: white" id="searchTextResults">
<tr><th>Name</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.name}}</td>
</tr>
</table>
</div>
<script>
var expectFriendNames = function (expectedNames, key) {
element.all(by.repeater(key + ' in friends').column(key + '.name')).then(function (arr) {
arr.forEach(function (wd, i) {
expect(wd.getText()).toMatch(expectedNames[i]);
});
});
};
it('should search across all fields when filtering with a string', function () {
var searchText = element(by.model('searchText'));
searchText.clear();
searchText.sendKeys('m');
searchText.clear();
searchText.sendKeys('2');
});
</script>
答案 0 :(得分:1)
仅在搜索文本不为空白时显示表格:
<table ng-show="searchText.length != 0">