如何在集合中的数组内搜索meteor?

时间:2016-02-26 09:15:39

标签: javascript meteor meteor-easy-search

我有以下两种模式,

Schema.extraOptions = new SimpleSchema({

name: {
    type: String
},
content: {
    type: String
},
note: {
    type: String
}

});



var wordFields = {
_id: {
    type: String,
    optional: true,
    autoform: {
        omit: true
    }
},
name: {
    type: String,
    label: 'Name'
}
'extraOptions.$': {
    type: Schema.extraOptions,
    optional: true
}
};

如何在wordFields中搜索name,extraOptions.name和extraOptions.content?

我尝试使用easySearch,但它没有按预期工作。

WordsIndex = new EasySearch.Index({
collection: Words,
fields: ['name', '_id', 'extraOptions' ],
selectorPerField: function (field, searchString) {
    console.log("searchString " + searchString);
    console.log("field " + field);
    if ('extraOptions' === field) {
        // return this selector if the email field is being searched
        console.log("searchString " + searchString);
        console.log("field " + field);
        return {
            extraOptions: {
                $elemMatch: {
                    name: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' },
                    content: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' }
                }
            }
        };
    }
    return this.defaultConfiguration().selectorPerField(field, searchString);
},

engine: new EasySearch.Minimongo()
});

在这种情况下,哪种方式最适合搜索值?

1 个答案:

答案 0 :(得分:0)

看看这个Link。这里说您应该使用关键字this

访问变量
相关问题