2014-05-12 60 views
0

好吧,所以我试图使用Windows Azure Table Service和节点来提取数据。Windows Azure和JavaScript多个子句条款

数据在那里,很好,我想要它,我唯一的问题是与多个where子句,我不知道或无法找到热文件在JavaScript中做它们。我没有使用C#,因此我能找到的大多数文档都没有用。

我已经猜到了几件事情,但没有工作......

function setCountryResultsWithAge(country, minAge, maxAge) { 
    var query = azure.TableQuery 
    .select() 
    .from('dwadatastorage') 
    .where('PartitionKey eq ? ' + country + ' and Age ge ? ' + minAge + ' and Age le ? ' + maxAge); 
    //I've also tried this 
    //and 
    // .where('Age ge ?', minAge) 
    //.and 
    // .where('Age le ?', maxAge); 
    //I've tried this as well 
    // .where('Age ge ?', minAge) 
    // .where('Age le ?', maxAge); 
    tableService.queryEntities(query, function(error, entities){ 
    if(!error){ 
     var countryMusicians = []; 
     for(var i in entities){ 
     //console.log(entities[i]); 
     countryMusicians.push([entities[i].Artist, entities[i].TotalPlays,  entities[i].Age]); 
     } 
     console.log(countryMusicians); 
     distributeCountryArtists(country, countryMusicians); 
    } 
    }); 
    console.log("Finished with age query maybe"); 
} 

如果有人知道更多,请帮助

的JavaScript才真正。

应该只是一个小的语法变化,但它不是什么我知道所有

回答

1

如果年龄存储为一个号码,请确保您用数字查询像这样:

var query = azure.TableQuery 
    .select() 
    .from('dwadatastorage') 
    .where('PartitionKey eq ? ', country) 
    .and('Age ge ? ', parseInt(minAge)) 
    .and('Age le ? ', parseInt(maxAge)); 
+0

的JavaScript把它作为一个int,只是当Azure的决定使用它,它一定是忘了。 谢谢 – WebTim

0

试试这个:

var query = azure.TableQuery 
    .select() 
    .from('dwadatastorage') 
    .where('PartitionKey eq ?', country) 
    .and('Age ge ?', minAge) 
    .and('Age le ?', maxAge); 

您问号应作为查询的占位符。在您的原始代码中,由于您没有提供函数调用的第二个参数,因此它们会被字面解释。

.where('PartitionKey eq ' + country + ' and Age ge ' + minAge + ' and Age le ' + maxAge); 

我相信也可以,但不推荐。