Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流星中的实例搜索_Javascript_Meteor - Fatal编程技术网

Javascript 流星中的实例搜索

Javascript 流星中的实例搜索,javascript,meteor,Javascript,Meteor,我有以下资料: UT.insert({ "chatUsers": [{ firstName: "John", lastName: "Doe" }, { firstName: "Anna", lastName: "Smith"

我有以下资料:

UT.insert({
            "chatUsers": [{
                        firstName: "John",
                        lastName: "Doe"
                    }, {
                        firstName: "Anna",
                        lastName: "Smith"
                    }, {
                        firstName: "Peter",
                        lastName: "Jones"
                    }
我用正则表达式编写了以下代码来遍历数组:

var selector = {
    chatUsers: [{
        firstName: regExp
    }, {
        lastName: regExp
    }]
};
console.log("UA" + UT.find(selector, options).fetch())
但它什么也不退。建议我这样做

这是我的代码:

if (searchText) {
    console.log("searchText")
    var regExp = buildRegExp(searchText);
    var selector = {
        chatUsers: [{
            firstName: regExp
        }, {
            lastName: regExp
        }]
    };
    console.log("UA" + UT.find(selector, options).fetch())

    return UT.find(selector, options).fetch();

} else {
    return UT.find({}, options).fetch();
}
});
我在这里写下了这样一句话:

function buildRegExp(searchText) {
    // this is a dumb implementation
    var parts = searchText.trim().split(/[ \-\:]+/);
    return new RegExp("(" + parts.join('|') + ")", "ig");
}
这很好用 在javascript中使用正则表达式之前,请尝试对其进行故障排除。
var regExp = buildRegExp(searchText);
console.log("searchText :" + regExp)
var selector = {chatUsers: { $all: [
{ "$elemMatch" : { firstName: {$regex:regExp}, {$regex:regExp} }   },                                   
                              ]
              }}
console.log("serach Result ::"+UT.find(selector).fetch())
//This where I have wrote the expression:
function buildRegExp(searchText) {

return new RegExp("^"+searchText,"ig")
}