0

我试图让流星在用户键入时搜索用户名。例如,输入“a”会给用户“admin”、“adam”和“apple”。“ad”会给“admin”、“adam”等。

在控制器中我有:

this.helpers({
  users() {
    return Meteor.users.find({username:this.searchText});
  }
});

在我的模板中

<ion-content>
<div class="new-chat.search">
  <label class="item item-input">
        <input ng-model="searchText" type="search" placeholder="Enter a username">
      </label>
	</div>
    <div class="list">
      <a ng-repeat="user in chat.users" ng-click="chat.newChat(user._id)" class="item">
        <h2>{{ user.username }}</h2>
		<h3>{{ user.profile.name }}</h3>
      </a>
    </div>
  </ion-content>

如果“this.searchText”更改为“admin”,它将返回 admin。

任何人都知道我需要做什么才能让这个工作?

4

1 回答 1

0

我猜你想搜索部分匹配。您可以为此使用正则表达式。 https://docs.mongodb.com/manual/reference/operator/query/regex/

例如:

return Meteor.users.find({username: $regex: {this.searchText, $options: 'i'}});
于 2016-06-26T17:01:35.373 回答