0
讓我們看看以下數據:
數據表1:嘗試使用結果從一個查詢到在parse.com來自新的查詢結果相結合 - JavaScript的
item1 item2
1 1
1 2
1 3
2 1
2 4
數據表2:
item1 nameItem1
1 fred
2 sam
我正在嘗試編寫一個javascript查詢,它將首先根據item2
從table1
中檢索數據。
然後,它會使用該結果中的item1,並搜索table2作爲名稱。
而對於輸出,我會得到如下:
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();
您已經在var query2 = Parse.Query(semclass);中忘記了「new」。它應該是var query2 = new Parse.Query(semclass); – 2014-10-09 09:45:43