无法根据数组中的值进行多个查询?

时间:2015-12-23 00:19:40

标签: javascript node.js mongodb sails.js waterline

简单地说,我希望我的用户能够在搜索字段中输入各种SKU和UPC(逗号分隔),在该搜索字段中我生成一组搜索值并执行迭代过程以返回结果/逻辑每个值(即1个UPC可以代表3个SKU,我会为搜索到的UPC产品返回最便宜的SKU)。

  • 带有UPC的产品可从Product.js找到。
  • 带有SKU的产品可从vendorProduct.js找到。

我想要做的一个例子:

// Search Array: UPC, SKU, SKU respectively.
var searchParams = ['342421111', '77HE2', 'U7IA2'];

// Declare var to hold search results.
var searchResults = {};

// For each value in array, get me results to work with.
for(i=0; i < searchParams.length; i++ ) {

    Product.find({"UPC": searchParams[i]}).exec(function (err, results){
        if(results.length >= 1) {
            data[searchParams[i]] = results;
        } else {
            vendorProduct.find({"SKU": searchParams[i]}).exec(function (err, results){
                if(results.length >= 1) {
                    data[searchParams[i]] = results;
                } else {
                    data[searchParams[i]] = "No results.";                    
                }
            });
        }
    });

}


console.log(searchResults);
// This should return something like the below:

{
    '342421111': [results inside],
    '77HE2': [results inside],
    'U7IA2': [results inside]
}

我已经查看了lodashasync.js等选项,但我不确定它是否解决了我想要做的事情。

我希望你们中的一个神奇的巫师可以帮助我!

1 个答案:

答案 0 :(得分:0)

看看async.map()

用法将是......

Dim lastr As Long
Dim lastrmale As Long
Dim lastrfemale As Long
Dim lastrmix As Long
Dim malesheet As Worksheet
Dim Femalesheet As Worksheet
Dim mixsheet As Worksheet
Dim i As Long
Set malesheet = Worksheets("Male")
Set Femalesheet = Worksheets("Female")
Set mixsheet = Worksheets("mix")
lastrmale = malesheet.Range("A" & malesheet.Range("A1").SpecialCells(xlLastCell).Row + 1).End(xlUp).Row

lastrfemale = Femalesheet.Range("A" & Femalesheet.Range("A1").SpecialCells(xlLastCell).Row + 1).End(xlUp).Row

lastr = WorksheetFunction.Min(lastrmale, lastrfemale)
lastrmix = 2
For i = 2 To lastr

    If (malesheet.Range("A" & i).value = Femalesheet.Range("A" & i).value) And (malesheet.Range("K" & i).value = Femalesheet.Range("K" & i).value) And (malesheet.Range("M" & i).value = Femalesheet.Range("M" & i).value) Then

        malesheet.Rows(i & ":" & i).Copy
        mixsheet.Range("A" & lastrmix).PasteSpecial xlPasteAll
    lastrmix = lastrmix + 1
    Femalesheet.Rows(i & ":" & i).Copy
        mixsheet.Range("A" & lastrmix).PasteSpecial xlPasteAll
    lastrmix = lastrmix + 1

    End If
Next
相关问题