1

我正在尝试在Node.js中为MongoDB动态构建查询。创建它的函数是:

    app.set('searchTerm', function (field, str){
        var i, searchTerm, keywords;
        keywords = str.split(' ');
        searchTerm = {field : str , _keywords : keywords};
        return searchTerm;
    });

我的问题是构造的对象最终以字符串“字段”作为键,而不是传递的参数。我如何得到它来评估论点?

4

1 回答 1

2
app.set('searchTerm', function (field, str){
    var i, searchTerm, keywords;
    keywords = str.split(' ');
    searchTerm = {_keywords: keywords};
    searchTerm[field] = str;
    console.dir(searchTerm);
    return searchTerm;
});
于 2012-11-05T23:29:17.867 回答