1

我正在构建一个网站,使用 angularJs 和 mongoDB 和 restheart,来构建一个数据库。

在此处输入图像描述

我的输入是这样写的,

        <th><input types="number" ng-model="GeneN" ng-change="change()"></th>
        <th><input types="number" ng-model="Des" ng-change="change()"></th>
        <th><input types="number" ng-model="Org" ng-change="change()"></th>
        <th><input types="number" ng-model="Site" ng-change="change()"></th>

我的过滤器参数是

$scope.change = function(){
        $http.get("http://localhost:3000/pupdb/pupdb/?count&pagesize=10&filter={'uniprot_AC':{'$regex':'(?i)"+$scope.UniP+".*'},'gene_name':{'$regex':'(?i)"+$scope.GeneN+".*'},'species':{'$regex':'(?i)"+$scope.Org+".*'},'description':{'$regex':'(?i)"+$scope.Des+".*'},'site':{'$regex':'(?i)"+$scope.Site+".*'}}")

事实证明,我必须在所有 5 个输入区域中输入文本或空格,然后才能激活过滤器并返回结果。之后,我可以在一个区域输入,其他4个空白,结果显示。似乎一个输入不足以触发过滤器。

我尝试使用 ng-init 并使用一个空格并且没有一个空格,但它根本不起作用。只有在 ng-init 中有一个字符时,才会触发过滤器。

我在想restheart过滤器中的“或”参数是否可以解决问题?如果是这样,请告诉我怎么写。

我应该怎么做才能解决这个问题?

4

1 回答 1

0

将几个值传递给过滤器qparam 实际上将使用 AND 运算符链接它们。

如果你想使用或尝试类似的东西(我还没有测试过):

$http.get("http://localhost:3000/pupdb/pupdb/?count&pagesize=10&filter={'$or': [{ "description" : { "$regex" : "(?i)\"+$scope.Des+\".*" }}, {  "gene_name" : { "$regex" : "(?i)\"+$scope.GeneN+\".*" }}, {  "site" : { "$regex" : "(?i)\"+$scope.Site+\".*" }}, {  "species" : { "$regex" : "(?i)\"+$scope.Org+\".*" }}, {  "uniprot_AC" : { "$regex" : "(?i)\"+$scope.UniP+\".*" }}]")

https://docs.mongodb.org/manual/reference/operator/query/or/

于 2016-01-07T10:22:04.290 回答