【发布时间】:2014-04-26 17:01:41
【问题描述】:
我正在使用AngularUI-Bootstrap的typeahead
<input type="text" name="recipient" id="recipient" placeholder="Friend's name or username"
autofocus="autofocus"
class="form-control"
ng-model="payment.recipient"
typeahead="friend.username for friend in friends | filter:$viewValue | limitTo:4"
typeahead-template-url="typeaheadTemplate.html"
typeahead-editable="false"
ng-required="true"/>
每个 Friend 对象具有以下结构:
{
name: friendship.name,
username: friendship.username,
picture: friendship.picture // Url
}
允许用户按图片搜索(它是头像的url)没有意义,并且修改过滤器没有成功。
我尝试过的:
typeahead="friend.username for friend in friends| filter:{username:username, name:name} | filter:$viewValue | limitTo:4"
typeahead="friend.username for friend in friends | filter:{username:$viewValue, name:$viewValue} | limitTo:4"
在过滤器表达式上使用$viewValue 两次似乎会破坏它...有什么想法吗?
【问题讨论】:
-
这是翻译错字还是您的代码实际上看起来像:“friend.username for friend forfriend”
-
@RobJacobs 这是一个翻译错字。修好了。
-
它似乎在做一个“和”过滤器($viewValue 匹配名称和用户名)而不是一个“或”过滤器。
-
在此处查看 plunk:plnkr.co/edit/EOmc7SWJaukcpMsKKKgQ?p=preview 基于此处的问题:stackoverflow.com/questions/16045069/…
标签: angularjs angular-ui-bootstrap