尝试使用parse.com-javascript中一个查询的结果与新查询的结果组合
Trying to use results from one query to combine with results from new query in parse.com - javascript
让我们考虑以下数据:
数据表1:
item1 item2
1 1
1 2
1 3
2 1
2 4
数据表2:
item1 nameItem1
1 fred
2 sam
我正在尝试编写一个javascript查询,它将首先从基于item2
的table1
中检索数据
然后,它将使用该结果中的item1,并在表2中搜索该名称
对于输出,我会得到以下内容:
item2 nameItem1
1 fred
1 sam
我正在使用parse.com作为我的数据库,但在这方面失败得很惨。以下是我的javascript代码示例:
var className = "seminarAttendance"; //change this to the appropriate class name
var query = new Parse.Query(className);
query.equalTo("StudentID", attendancesearch.studentID.value);
query.find({
success: function(results) {
if(results.length==0){
alert("Sorry, there are no results that match your search.")
{return;}}
var w = window.open();
w.document.write('<html><head><title>Result Table</title>');
w.document.write('<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css" >');
w.document.write('<link rel="stylesheet" href="tablesearch.css" type="text/css" />');
w.document.write(' </head><body><h3> Here are your search results!</h3><br/>');
w.document.write(' Student # ' + attendancesearch.studentID.value + ' has attended ' +results.length + ' seminars <br>');
w.document.write('<div class="search"><table class="table table-bordered table-condensed table-striped" >');
w.document.write('<thead><tr><td><b>Seminar ID</b></td><td><b>Student ID</b></td><td><b>Time Period</b></td><td><b>Student ID</b></td><td><b>Student ID</b></td></tr></thead><tbody>');
for (var i=0; i < results.length; i++){
var object = results[i];
var semid = object.get("SeminarID");
var studid=object.get("StudentID");
var timeper=object.get("timePeriodID");
var semclass = "seminarTable";
var query2 = Parse.Query(semclass);
query2.equalTo("seminarID", semid);
query2.first({
success: function(q2object){
var test = q2object.get("seminarName");
},
});
w.document.write('<tr>');
w.document.write('<td>' + semid + '</td>');
w.document.write('<td>' + studid + '</td>');
w.document.write('<td>' + timeper + '</td>');
w.document.write('<td>' + test + '</td>');
w.document.write('</tr>');
}
w.document.write('</tbody></table></div></body></html>');
w.document.close();
不能在'for'循环中调用query2。因为查询需要一些时间,这比执行"for"循环要长得多。相反,您可以获取"seminarTable"类的所有对象,并将它们存储在另一个数组中(比如results1)。现在我们有了results和results1数组,所以您可以手动搜索并放置条件。
var className = "seminarAttendance"; //change this to the appropriate class name
var query = new Parse.Query(className);
query.equalTo("StudentID", attendancesearch.studentID.value);
query.find({
success: function(results) {
if(results.length==0){
alert("Sorry, there are no results that match your search.")
{return;}}
var w = window.open();
w.document.write('<html><head><title>Result Table</title>');
w.document.write('<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css" >');
w.document.write('<link rel="stylesheet" href="tablesearch.css" type="text/css" />');
w.document.write(' </head><body><h3> Here are your search results!</h3><br/>');
w.document.write(' Student # ' + attendancesearch.studentID.value + ' has attended ' +results.length + ' seminars <br>');
w.document.write('<div class="search"><table class="table table-bordered table-condensed table-striped" >');
w.document.write('<thead><tr><td><b>Seminar ID</b></td><td><b>Student ID</b></td><td><b>Time Period</b></td><td><b>Student ID</b></td><td><b>Student ID</b></td></tr></thead><tbody>');
var semclass = "seminarTable";
var query2 = Parse.Query(semclass);
query2.find({
success: function(results1){
//Do whatever you want here
w.document.write('<tr>');
w.document.write('<td>' + semid + '</td>');
w.document.write('<td>' + studid + '</td>');
w.document.write('<td>' + timeper + '</td>');
w.document.write('<td>' + test + '</td>');
w.document.write('</tr>');
},
});
}
w.document.write('</tbody></table></div></body></html>');
w.document.close();
相关文章:
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- 如何将这些查询结果放入表中
- 有关PouchDB的复杂startkey/endkey查询未返回预期结果
- 如何在下拉列表更改时自动填充mysql查询结果中的文本框值
- 将数据库中的超链接添加到查询结果
- onchange选择get value并执行查询,然后在同一页面上显示结果
- 为什么我的文本框没有用查询结果更新
- 如何将mysql查询的结果获取到html文本框中
- 使用jquery显示mysql查询结果
- 需要呈现MongoDB查询返回结果的特定索引/位置
- 如何使用 angularjs 以表格格式显示 parse.com 的查询结果
- Meteor:在模板接受Mongo查询结果之前修改它的最佳实践
- 未捕获的范围错误:WebSQL查询结果中的项索引超出范围错误
- 返回解析云代码关系查询的结果
- 自定义查询字符串分析器返回不正确的结果
- 表单提交后保留数据库查询结果
- 从sqlite数据库查询数据结果文件名
- 如何显示查询回调数据结果仅从开始
- 在模板帮助程序中连接两个查询的结果
- 将结果查询到 JSON Laravel 5