我目前正在开发一个页面,该页面编译来自Business Catalyst内容管理系统中的Web应用程序提交的动态数据。 BC允许您创建以{tag_itemid}形式输出标签的webapps这些标签本质上是系统以其所代表的信息的形式输出的变量。
那说我有一个非常复杂的页面,从几个webapps中提取数据,将其输出到用户可以查看的生成的div中。我遇到了一些麻烦,但是在阅读我的数组页面时。我一直收到错误' Uncaught SyntaxError:Unexpected token ['错误出现在我的数组的开头,allQuestions {tag_itemid} [0]。
目前,忽略BC标签,它们并不会真正影响脚本。有一些WebApp标记填补了我可能会看到的传入我的数组的变量的空白。
如果您可以查看我的代码并告诉我为什么会收到错误,我将不胜感激,我已经尝试包含所有相关信息,而不会使代码过载。另外请注意,变量都是在页面上或我与您共享的部分之上定义的 - 我没有收到任何未定义的错误。
感谢您的帮助!
var questionAnswers{tag_itemid} = function(qNum, ACount, BCount, CCount, DCount, TCount, FCount, answerType, Rating, SAnswer, qText) {
this.qNum = qNum;
this.ACount = ACount;
this.BCount = BCount;
this.CCount = CCount;
this.DCount = DCount;
this.TCount = TCount;
this.FCount = FCount;
this.Rating = Rating;
this.SAnswer = SAnswer;
this.answerType = answerType;
this.avgAnswer = 0;
this.avgAnswerText = "";
this.formatSAnswers = function() {
var x = this.SAnswer
var y = x.join('"</p></div><div class="sAnswer-data"><p>"');
this.avgAnswer = y;
};
this.qavgAnswer = function() {
if (this.answerType != "" || this.anserType != " ") {
if (this.answerType == "Multiple Choice") {
if (this.ACount > this.BCount && this.ACount > this.CCount && this.ACount > this.DCount) {
this.avgAnswer = this.ACount;
this.avgAnswerText = "A was selected " + this.avgAnswer + " times";
} else if (this.BCount > this.ACount && this.BCount > this.CCount && this.BCount > this.DCount) {
this.avgAnswer = this.BCount;
this.avgAnswerText = "B was selected " + this.avgAnswer + " times";
} else if (this.CCount > this.ACount && this.CCount > this.BCount && this.CCount > this.DCount) {
this.avgAnswer = this.CCount;
this.avgAnswerText = "C was selected " + this.avgAnswer + " times";
} else if (this.DCount > this.ACount && this.DCount > this.BCount && this.DCount > this.CCount) {
this.avgAnswer = this.DCount;
this.avgAnswerText = "D was selected " + this.avgAnswer + " times";
} else if (this.ACount == this.Dcount) {
this.avgAnswer = this.ACount;
this.avgAsnwerText = "Both A and D selected: " + this.avgAnswer + " times.";
} else if (this.ACount == this.Bcount) {
this.avgAnswer = this.ACount;
this.avgAsnwerText = "Both A and B selected: " + this.avgAnswer + " times.";
} else if (this.ACount == this.Ccount) {
this.avgAnswer = this.ACount;
this.avgAsnwerText = "Both A and C selected: " + this.avgAnswer + " times.";
} else if (this.BCount == this.Acount) {
this.avgAnswer = this.BCount;
this.avgAsnwerText = "Both B and D selected: " + this.avgAnswer + " times.";
} else if (this.BCount == this.Ccount) {
this.avgAnswer = this.BCount;
this.avgAsnwerText = "Both B and C selected: " + this.avgAnswer + " times.";
} else if (this.CCount == this.Dcount) {
this.avgAnswer = this.CCount;
this.avgAsnwerText = "Both C and D selected: " + this.avgAnswer + " times.";
} else if (this.ACount == this.BCount && this.ACount == this.CCount) {
this.avgAnswer = this.ACount;
this.avgAnswerText = "Answer A, B, and C were selected: " + this.avgAnswer + " times.";
} else if (this.ACount == this.CCount && this.ACount == this.DCount) {
this.avgAnswer = this.ACount;
this.avgAnswerText = "Answer A, C, and D were selected: " + this.avgAnswer + " times.";
} else if (this.BCount == this.CCount && this.BCount == this.DCount) {
this.avgAnswer = this.BCount;
this.avgAnswerText = "Answer B, C, and D were selected: " + this.avgAnswer + " times.";
} else if (this.ACount == 0 && this.ACount == this.BCount && this.ACount == this.CCount && this.ACount == this.DCount) {
this.avgAnswerText = "There were no selections made for this question.";
} else {
this.avgAnswer = this.ACount;
this.avgAnswerText = "All selections are equal. Answers A, B, C, and D were selected " + this.ACount + " times each.";
};
this.correctAText = "The correct answer:<br/><br/>" + this.avgAnswer;
} else if (this.answerType == "True/False") {
if (this.TCount > this.FCount) {
this.avgAnswer = this.TCount;
this.avgAnswerText = "True was selected " + this.avgAnswer + " times.";
} else if (this.TCount < this.FCount) {
this.avgAnswer = this.FCount;
this.avgAnswerText = "False was selected " + this.avgAnswer + " times.";
} else if (this.TCount == 0 && this.TCount == this.FCount) {
this.avgAnswer = this.TCount;
this.avgAnswerText = "There is not enough data to calculate the average user-selected answer for this question.";
} else {
this.avgAnswer = this.TCount;
this.avgAnswerText = "Both True and False were selected " + this.avgAnswer + " times.";
};
this.correctAText = "The correct answer:<br/><br/>" + this.avgAnswer;
} else if (this.answerType == "Ratings") {
this.correctAText = "This question is evaluated with survey ratings.";
this.Rating = this.Rating / ch{tag_itemid}_userCompletes;
this.avgAnswer = this.Rating;
this.avgAnswerText = "The average rating for this question is " + this.avgAnswer;
} else {
this.correctAText = "This question is evaluated with survey short answers.";
this.formatSanswers();
this.avgAnswerText = 'This question is a short answer survey. Click the button below to see some of the answers.<br/><br/><a class="button small">View responses</a></p></div><div><p class="sAnswer-data">';
};
} else {
this.avgAnswerText = "There is no data for this question. Please try again at a later time.";
};
};
this.insertInfo = function(divID) {
document.getElementById(divName).innerHTML = '<div class="row"><div class="small-12 columns" id="q' + this.qNum + '_text"><p><span class="qNum-data">' + this.qNum + '</span>' + this.qText + '</p></div><div class="row"><div class="small-12 medium-6 columns" id="qAvgAnser' + this.qNum + '"><p class="avgA-data">' + this.avgAnswerText + '</p></div><div class="small-12 medium-6 columns"><p class="avgA-data">' + this.correctAnswer + '</p></div></div></div>';
};
this.showData = function() {
resource = document.createElement('div');
addID = document.createAttribute("id");
divName = "ch{tag_itemid}_ch{tag_chapter number}_q" + this.qNum;
addID.value = divName;
resource.setAttributeNode(addClass);
insertInfo(divName);
};
this.generateInfo(passedDivID) = function() {
passedDivID = passedDivID + this.showData();
};
};
请注意,这是实际数组,我将其限制为4个元素,而不是实际存在的15个元素。
var allQuestions{tag_itemid} = [];
var allQuestions{tag_itemid}[0] = questionAnswers{tag_itemid}("1", ch{tag_itemid}_ch{tag_chapter number}QAavg1, ch{tag_itemid}_ch{tag_chapter number}QBavg1, ch{tag_itemid}_ch{tag_chapter number}QCavg1, ch{tag_itemid}_ch{tag_chapter number}QDavg1, ch{tag_itemid}_ch{tag_chapter number}QTavg1, ch{tag_itemid}_ch{tag_chapter number}QFavg1, ch{tag_itemid}_ch{tag_chapter number}qAType1, ch{tag_itemid}_ch{tag_chapter number}Rate1Q, ch{tag_itemid}_ch{tag_chapter number}SA1Q, ch{tag_itemid}_ch{tag_chapter number}QText1);
var allQuestions{tag_itemid}[1] = questionAnswers{tag_itemid}("2", ch{tag_itemid}_ch{tag_chapter number}QAavg2, ch{tag_itemid}_ch{tag_chapter number}QBavg2, ch{tag_itemid}_ch{tag_chapter number}QCavg2, ch{tag_itemid}_ch{tag_chapter number}QDavg2, ch{tag_itemid}_ch{tag_chapter number}QTavg2, ch{tag_itemid}_ch{tag_chapter number}QFavg2, ch{tag_itemid}_ch{tag_chapter number}qAType2, ch{tag_itemid}_ch{tag_chapter number}Rate2Q, ch{tag_itemid}_ch{tag_chapter number}SA2Q, ch{tag_itemid}_ch{tag_chapter number}QText2);
var allQuestions{tag_itemid}[2] = questionAnswers{tag_itemid}("3", ch{tag_itemid}_ch{tag_chapter number}QAavg3, ch{tag_itemid}_ch{tag_chapter number}QBavg3, ch{tag_itemid}_ch{tag_chapter number}QCavg3, ch{tag_itemid}_ch{tag_chapter number}QDavg3, ch{tag_itemid}_ch{tag_chapter number}QTavg3, ch{tag_itemid}_ch{tag_chapter number}QFavg3, ch{tag_itemid}_ch{tag_chapter number}qAType3, ch{tag_itemid}_ch{tag_chapter number}Rate3Q, ch{tag_itemid}_ch{tag_chapter number}SA3Q, ch{tag_itemid}_ch{tag_chapter number}QText3);
var allQuestions{tag_itemid}[3] = questionAnswers{tag_itemid}("4", ch{tag_itemid}_ch{tag_chapter number}QAavg4, ch{tag_itemid}_ch{tag_chapter number}QBavg4, ch{tag_itemid}_ch{tag_chapter number}QCavg4, ch{tag_itemid}_ch{tag_chapter number}QDavg4, ch{tag_itemid}_ch{tag_chapter number}QTavg4, ch{tag_itemid}_ch{tag_chapter number}QFavg4, ch{tag_itemid}_ch{tag_chapter number}qAType4, ch{tag_itemid}_ch{tag_chapter number}Rate4Q, ch{tag_itemid}_ch{tag_chapter number}SA4Q, ch{tag_itemid}_ch{tag_chapter number}QText4);
这是与数组交互的脚本:
for (var i = 0; i <= 14; i++) {
if (allQuestions[i].qText != "" || allQuestions[i].qText != " ") {
allQuestions[i].qavgAnswer();
allQuestions[i].generateInfo(quizDiv{tag_itemid});
};