0

我目前正在处理一个页面,该页面从 Business Catalyst 内容管理系统中的 Web 应用程序提交中编译动态数据。BC 允许您创建以 {tag_itemid} 形式输出标签的 Web 应用程序,这些标签本质上是系统以它所代表的信息形式输出的变量。

也就是说,我有一个非常复杂的页面,它从几个 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});
        };         
4

0 回答 0