我正在使用mongoose / mongodb编写node.js Web应用程序。 我无法弄清楚我的代码有什么问题。 我在下面得到了这个错误,并且有我写的代码。
SyntaxError:
意外的令牌{in /home/ubuntu/workspace/combatSports/views/fighter/show.ejs while 编译ejs 在功能(本机) 在Object.Template.compile(/home/ubuntu/workspace/combatSports/node_modules/ejs/lib/ejs.js:491:12) at Object.compile(/home/ubuntu/workspace/combatSports/node_modules/ejs/lib/ejs.js:30:16) 在handleCache(/home/ubuntu/workspace/combatSports/node_modules/ejs/lib/ejs.js:169:18) 在View.exports.renderFile [作为引擎](/home/ubuntu/workspace/combatSports/node_modules/ejs/lib/ejs.js:374:14) 在View.render(/home/ubuntu/workspace/combatSports/node_modules/express/lib/view.js:126:8) 在tryRender(/home/ubuntu/workspace/combatSports/node_modules/express/lib/application.js:639:10) 在EventEmitter.render(/home/ubuntu/workspace/combatSports/node_modules/express/lib/application.js:591:3) 在ServerResponse.render(/home/ubuntu/workspace/combatSports/node_modules/express/lib/response.js:960:7) 在/home/ubuntu/workspace/combatSports/app.js:127:17 在查询。 (/home/ubuntu/workspace/combatSports/node_modules/mongoose/lib/model.js:3343:16) at /home/ubuntu/workspace/combatSports/node_modules/mongoose/node_modules/kareem/index.js:259:21 at /home/ubuntu/workspace/combatSports/node_modules/mongoose/node_modules/kareem/index.js:127:16 at nextTickCallbackWith0Args(node.js:420:9) at process._tickCallback(node.js:349:13)
我的代码是:
<% var significantStrikeLanded = 0; %>
<% var totalTimeinsec = 0; %>
<% var totalSignificantStrikeLanded = 0; %>
<% var totalSignificantStrikeThrows = 0; %>
<% var totalStrikeAbsorbed = 0; %>
<% var totalStrikeEnemyThrows = 0; %>
<% var totalStrikeEnemyLanded = 0; %>
<% var totalTakeDowns = 0; %>
<% var totalTakeDownAttempts = 0; %>
<% var totalTakeDownEnemyAttempts = 0; %>
<% var totalTakeDownsEnemyDid = 0; %>
<% var totalSubmissionAttempts = 0; %>
<% var totalWin = 0; %>
<% var totalLoss = 0; %>
<% var totalDraw = 0;%>
<% var timeInsec = 0; %>
<% var totalNocontest = 0; %>
<% var totalKO = 0; %>
<% var totalSubmission = 0; %>
<% var totalDecision = 0; %>
<% var strikeScoreTotal = 0; %>
<% fighter.fights.forEach(function(fight) { %>
<% if (fighter.firstName == fight.fighters[0].fighter.firstName && fighter.lastName == fight.fighters[0].fighter.lastName) { %>
<% totalTimeinsec = totalTimeinsec + ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec);%>
<% totalSignificantStrikeLanded = totalSignificantStrikeLanded + fight.fighters[0].significantStrikeLanded; %>
<% totalSignificantStrikeThrows = totalSignificantStrikeThrows + fight.fighters[0].significantStrikeThrow; %>
<% totalStrikeAbsorbed = totalStrikeAbsorbed + fight.fighters[1].significantStrikeLanded; %>
<% totalStrikeEnemyThrows = totalStrikeEnemyThrows + fight.fighters[1].significantStrikeThrow; %>
<% totalStrikeEnemyLanded = totalStrikeEnemyLanded + fight.fighters[1].significantStrikeLanded; %>
<% totalTakeDowns = totalTakeDowns + fight.fighters[0].takeDowns; %>
<% totalTakeDownAttempts = totalTakeDownAttempts + fight.fighters[0].takeDownAttempts; %>
<% totalTakeDownEnemyAttempts = totalTakeDownEnemyAttempts + fight.fighters[1].takeDownAttempts; %>
<% totalTakeDownsEnemyDid = totalTakeDownsEnemyDid + fight.fighters[1].takeDowns; %>
<% totalSubmissionAttempts = totalSubmissionAttempts + fight.fighters[0].submissionAttempts; %>
<% if(fight.fighters[0].result == "win") { %>
<% totalWin++; %>
<% } else if (fight.fighters[0].result == "loss") { %>
<% totalLoss++; %>
<% } else if (fight.fighters[0].result == "draw") { %>
<% totalDraw++; %>
<% } else if (fight.fighters[0].result == "nocontest") { %>
<% totalNocontest++; %>
<% } %>
<% if (fight.info.method == "ko") { %>
<% totalKO++; %>
<% } else if(fight.info.method == "submission") { %>
<% totalSubmission++; %>
<% } else if(fight.info.method == "decision") { %>
<% totalDecision++; %>
<% } %>
<% timeInsec = ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec;%>
<% strikeScore = (fight.fighters[0].significantStrikeLanded / (timeInsec * 60)) / (fight.fighters[1].significantStrikeLanded / (timeInsec * 60)) + (fight.fighters[0].significantStrikeLanded / fight.fighters[0].significantStrikeThrow) / (fight.fighters[1].significantStrikeLanded / fight.fighters[1].significantStrikeThrow) + (((fight.info.method == "ko" && fight.fighters[0].result == "win") ? 1 : 0) - 1) * 100; %>
<% strikeScoreTotal = strikeScoreTotal + strikeScore; %>
<% } else if (fighter.firstName == fight.fighters[1].fighter.firstName && fighter.lastName == fight.fighters[1].fighter.lastName) { %>
<% totalTimeinsec = totalTimeinsec + ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec);%>
<% totalSignificantStrikeLanded = totalSignificantStrikeLanded + fight.fighters[1].significantStrikeLanded; %>
<% totalSignificantStrikeThrows = totalSignificantStrikeThrows + fight.fighters[1].significantStrikeThrow; %>
<% totalStrikeAbsorbed = totalStrikeAbsorbed + fight.fighters[0].significantStrikeLanded; %>
<% totalStrikeEnemyThrows = totalStrikeEnemyThrows + fight.fighters[0].significantStrikeThrow; %>
<% totalStrikeEnemyLanded = totalStrikeEnemyLanded + fight.fighters[0].significantStrikeLanded; %>
<% totalTakeDowns = totalTakeDowns + fight.fighters[1].takeDowns; %>
<% totalTakeDownAttempts = totalTakeDownAttempts + fight.fighters[1].takeDownAttempts; %>
<% totalTakeDownEnemyAttempts = totalTakeDownEnemyAttempts + fight.fighters[0].takeDownAttempts; %>
<% totalTakeDownsEnemyDid = totalTakeDownsEnemyDid + fight.fighter1.takeDowns; %>
<% totalSubmissionAttempts = totalSubmissionAttempts + fight.fighters[1].submissionAttempts; %>
<% if(fight.fighters[1].result == "win") { %>
<% totalWin++; %>
<% } else if (fight.fighters[1].result == "loss") { %>
<% totalLoss++; %>
<% } else if (fight.fighters[1].result == "draw") { %>
<% totalDraw++; %>
<% } else if (fight.fighters[1].result == "nocontest") { %>
<% totalNocontest++; %>
<% } %>
<% if (fight.info.method == "ko") { %>
<% totalKO++; %>
<% } else if(fight.info.method == "submission") { %>
<% totalSubmission++ ;%>
<% } else if(fight.info.method == "decision") { %>
<% totalDecision++; %>
<% } %>
<% timeInsec = ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec;%>
<% strikeScore = (fight.fighters[1].significantStrikeLanded / (timeInsec * 60)) / (fight.fighters[0].significantStrikeLanded / (timeInsec * 60)) + (fight.fighters[1].significantStrikeLanded / fight.fighters[1].significantStrikeThrow) / (fight.fighters[0].significantStrikeLanded / fight.fighters[0].significantStrikeThrow) + (((fight.info.method == "ko" && fight.fighters[1].result == "win") ? 1 : 0) - 1) * 100; %>
<% strikeScoreTotal = strikeScoreTotal + strikeScore; %>
<% } %>
<% }) %>
答案 0 :(得分:0)
我在这里看到两个问题。
在这一行
<% totalTimeinsec = totalTimeinsec + ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec);%>
在)
;
在这一行
<% totalTimeinsec = totalTimeinsec + ((fight.info.round -1) * 300) + fight.info.min * 60 + fight.info.sec);%>
再次在)
;
希望这有帮助。