admin 管理员组文章数量: 1086019
I'm refining my ui.bootstrap typeahead adding some awesomness, but I'm struggling on this one.
I've created a small Plunker to demonstrate my issue:
Two words about the issue:
I have this array of objects which populate my $scope.data
but I'm not able to tell typeahead
to use only a particular field to search the result
$scope.data = [
{
name: 'Mario',
desc: 'Super Plumber',
id: 0,
type: 'good'
},
{
name: 'Luigi',
desc: 'Assistant Plumber',
id: 1,
type: 'good'
},
...
Whenever you search in the typeahead, you'll search for every field in the object, even type
and id
I've tried, without success, solution like these:
typeahead="datum.name as ( datum.name +', '+ datum.desc)
for datum in data | filter:$viewValue | limitTo:8"
---> no change
typeahead="datum as ( datum.name +', '+ datum.desc)
for datum.name in data | filter:$viewValue | limitTo:8"
--> no match
How can I restrict the search to, let's say, the name
field?
I'm refining my ui.bootstrap typeahead adding some awesomness, but I'm struggling on this one.
I've created a small Plunker to demonstrate my issue:
http://plnkr.co/edit/u2Le37?p=preview
Two words about the issue:
I have this array of objects which populate my $scope.data
but I'm not able to tell typeahead
to use only a particular field to search the result
$scope.data = [
{
name: 'Mario',
desc: 'Super Plumber',
id: 0,
type: 'good'
},
{
name: 'Luigi',
desc: 'Assistant Plumber',
id: 1,
type: 'good'
},
...
Whenever you search in the typeahead, you'll search for every field in the object, even type
and id
I've tried, without success, solution like these:
typeahead="datum.name as ( datum.name +', '+ datum.desc)
for datum in data | filter:$viewValue | limitTo:8"
---> no change
typeahead="datum as ( datum.name +', '+ datum.desc)
for datum.name in data | filter:$viewValue | limitTo:8"
--> no match
How can I restrict the search to, let's say, the name
field?
1 Answer
Reset to default 13The magical line is as following
filter:{name: $viewValue}
This would limit the search to only name field. Look at this document ion for ng-filter
Object: A pattern object can be used to filter specific properties on objects contained by array. For example {name:"M", phone:"1"} predicate will return an array of items which have property name containing "M" and property phone containing "1". A special property name $ can be used (as in {$:"text"}) to accept a match against any property of the object. That's equivalent to the simple substring match with a string as described above.
Plunker Updated
本文标签: javascriptSearch only a specific field in uibootstrap typeaheadStack Overflow
版权声明:本文标题:javascript - Search only a specific field in ui.bootstrap typeahead - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744027125a2520829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论