Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在对象名称中循环出现问题_Javascript_Oop_Object_Dynamic_For Loop - Fatal编程技术网

Javascript 在对象名称中循环出现问题

Javascript 在对象名称中循环出现问题,javascript,oop,object,dynamic,for-loop,Javascript,Oop,Object,Dynamic,For Loop,我是javascript新手,我正在尝试在BusinessCatalyst中创建一个动态问答问题列表。使用BC的设置方式,您可以使用{tags}将用户创建的信息放置在页面上 也就是说,我正试图根据用户选择的值生成一个测验问题列表。我创建了一个对象“Question”,并将必要的属性及其值放入下面新定义的对象中 在我的代码中,我当前正在尝试: 1-定义问题对象类 2-定义15个可能的测验问题 3-编写一个for循环,该循环将根据上一个问题的键值编写每个问题 我编写的function/for循环最终

我是javascript新手,我正在尝试在BusinessCatalyst中创建一个动态问答问题列表。使用BC的设置方式,您可以使用{tags}将用户创建的信息放置在页面上

也就是说,我正试图根据用户选择的值生成一个测验问题列表。我创建了一个对象“Question”,并将必要的属性及其值放入下面新定义的对象中

在我的代码中,我当前正在尝试:

1-定义问题对象类

2-定义15个可能的测验问题

3-编写一个for循环,该循环将根据上一个问题的键值编写每个问题

我编写的function/for循环最终将实现以下功能:

写问题1

如果问题1键的值为“是”,则填写问题2

如果问题2的键值为“是”,则填写问题3

等等,直到没有更多的是或者问题15已经写好

当我尝试执行下面的代码时,我得到错误“UncaughtReferenceError:QuestionNotDefined”,有人能帮我理解我做错了什么吗?谢谢你的帮助

注意:为了节省空间,我只包含了三个问题变量。在我的实际代码中,我定义了15个问题对象


功能问题(问题编号、问题文本、答案类型、答案A、答案B、答案C、答案D、正确答案、可视参考、参考键、下一个TQ、qTextField、aTypeField、McField、mcBField、McField、McField、mcUserAnswer、tfUserAnswer、sRatings、sSAnswer、passFail){
this.questionNumber=问题编号;
this.questionText=questionText;
this.answerType=answerType;
this.answerA=answerA;
this.answerB=answerB;
this.answerC=answerC;
this.answerD=answerD;
this.true=“true”;
this.false=“false”;
this.correctAnswer=correctAnswer;
this.visualRef=visualRef;
this.refKey=refKey;
this.nextQ=nextQ;
this.qTextField=qTextField;
this.aTypeField=aTypeField;
this.mcAField=mcAField;
this.mcBField=mcBField;
this.mcCField=mcCField;
this.mcDField=mcDField;
this.mcUserAnswer=mcUserAnswer;
this.tfUserAnswer=tfUserAnswer;
this.sRatings=sRatings;
this.sSAnswer=sSAnswer;
this.passFail=passFail;
this.createQuestion=函数(){
文件。书写(“这是书写问题”+这个问题编号);
};
};
新问题1=新问题1=新问题1=新问题1(“1“,,“{tag问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问1}“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,_q-vimeo_1}{tag_q-image_1_value}“{tag_q-下一个问题{u 1}”、“CAT_Custom_13”、“CAT_Custom_11”、“CAT_Custom_14”、“CAT_Custom_15”、“CAT_Custom_16”、“CAT_Custom_17”、“CAT_Custom_7”、“CAT_Custom_8”、“CAT_Custom_9”、“CAT_Custom__10”、“CAT_Custom__12”);
新问题(2“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,_q-vimeo_2}{tag_q-image_2_value}“{tag_q-下一个问题{u2}“,“CAT_Custom_19”,“CAT_Custom_20”,“CAT_Custom_22”,“CAT_Custom_23”,“CAT_Custom_24”,“CAT_Custom_25”,“CAT_Custom_21”,“CAT_Custom_26”,“CAT_Custom_27”,“CAT_Custom_28”,“CAT_Custom u29”);
新问题3=新问题3=新问题3=新问题3(“3“,,,“{tag问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问问3}“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“tag_q-vimeo_3}{tag_q-image_3_值}”{tag_q-下一个问题{u 3}”、“CAT_Custom_30”、“CAT_Custom_31”、“CAT_Custom_33”、“CAT_Custom_34”、“CAT_Custom_35”、“CAT_Custom_36”、“CAT_Custom_32”、“CAT_Custom_37”、“CAT_Custom_38”、“CAT_Custom__39”、“CAT_Custom__40”);

对于(var i=1;i您已经创建了3个单独的对象,您试图将它们作为数组访问,但是它们是单独的而不是数组

试试这个

var question = new Array();

question[1] = new Question("1", "{tag_q-question_1}", "{tag_q-answer-type_1}", "{tag_q-text-answer_101}", "{tag_q-text-answer_102}", "{tag_q-text-answer_103}", "{tag_q-text-answer_104}", "{tag_q-multichoice-answer_1}{tag_q-t/f-answer_1}", "{tag_q-visual-reference_1}", "{tag_q-youtube_1}{tag_q-vimeo_1}{tag_q-image_1_value}", "{tag_q-next-question_1}", "CAT_Custom_13", "CAT_Custom_11", "CAT_Custom_14", "CAT_Custom_15", "CAT_Custom_16", "CAT_Custom_17", "CAT_Custom_7", "CAT_Custom_8", "CAT_Custom_9", "CAT_Custom_10", "CAT_Custom_12");
question[2] = new Question("2", "{tag_q-question_2}", "{tag_q-answer-type_2}", "{tag_q-text-answer_201}", "{tag_q-text-answer_202}", "{tag_q-text-answer_203}", "{tag_q-text-answer_204}", "{tag_q-multichoice-answer_2}{tag_q-t/f-answer_2}", "{tag_q-visual-reference_2}", "{tag_q-youtube_2}{tag_q-vimeo_2}{tag_q-image_2_value}", "{tag_q-next-question_2}", "CAT_Custom_19", "CAT_Custom_20", "CAT_Custom_22", "CAT_Custom_23", "CAT_Custom_24", "CAT_Custom_25", "CAT_Custom_21", "CAT_Custom_26", "CAT_Custom_27", "CAT_Custom_28", "CAT_Custom_29");
question[3] = new Question("3", "{tag_q-question_3}", "{tag_q-answer-type_3}", "{tag_q-text-answer_301}", "{tag_q-text-answer_302}", "{tag_q-text-answer_303}", "{tag_q-text-answer_304}", "{tag_q-multichoice-answer_3}{tag_q-t/f-answer_3}", "{tag_q-visual-reference_3}", "{tag_q-youtube_3}{tag_q-vimeo_3}{tag_q-image_3_value}", "{tag_q-next-question_3}", "CAT_Custom_30", "CAT_Custom_31", "CAT_Custom_33", "CAT_Custom_34", "CAT_Custom_35", "CAT_Custom_36", "CAT_Custom_32", "CAT_Custom_37", "CAT_Custom_38", "CAT_Custom_39", "CAT_Custom_40");

for (var i = 1; i <= 3; i++) {
    if (question[i].nextQ === "Yes") {
        question[i].createQuestion();
    } else {
        question[1].createQuestion();
    };
}   
var-question=new-Array();
新问题(1)元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元tag_q-vimeo_1}{tag_q-image_1_value},“{tag_q-next-question_1}”“,”猫定制13“,”猫定制11“,”猫定制14“,”猫定制15“,”猫定制16“,”猫定制17“,”猫定制7“,”猫定制8“,”猫定制9“,”猫定制10“,”猫定制12“;
(2)新问题(2)元元元问问问(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)新问题(2)的“,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,{{{{{{{{{...................................................................tag_q-vimeo_2}{tag_q-image_2_值},“{tag_q-next-question_2}”“,”猫自定义19”,“猫自定义20”,“猫自定义22”,“猫自定义23”,“猫自定义24”,“猫自定义25”,“猫自定义21”,“猫自定义26”,“猫自定义27”,“猫自定义28”,“猫自定义29”);
(3)新问题(3)元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元{tag_q-vimeo_3}{tag_q-image_3_value},“{tag_q-next-question_3}”“,”猫定制30“,”猫定制31“,”猫定制33“,”猫定制34“,”猫定制35“,”猫定制36“,”猫定制32“,”猫定制37“,”猫定制38“,”猫定制39“,”猫定制40“;
对于(VarI=1;我不认为
var question = new Array();

question[1] = new Question("1", "{tag_q-question_1}", "{tag_q-answer-type_1}", "{tag_q-text-answer_101}", "{tag_q-text-answer_102}", "{tag_q-text-answer_103}", "{tag_q-text-answer_104}", "{tag_q-multichoice-answer_1}{tag_q-t/f-answer_1}", "{tag_q-visual-reference_1}", "{tag_q-youtube_1}{tag_q-vimeo_1}{tag_q-image_1_value}", "{tag_q-next-question_1}", "CAT_Custom_13", "CAT_Custom_11", "CAT_Custom_14", "CAT_Custom_15", "CAT_Custom_16", "CAT_Custom_17", "CAT_Custom_7", "CAT_Custom_8", "CAT_Custom_9", "CAT_Custom_10", "CAT_Custom_12");
question[2] = new Question("2", "{tag_q-question_2}", "{tag_q-answer-type_2}", "{tag_q-text-answer_201}", "{tag_q-text-answer_202}", "{tag_q-text-answer_203}", "{tag_q-text-answer_204}", "{tag_q-multichoice-answer_2}{tag_q-t/f-answer_2}", "{tag_q-visual-reference_2}", "{tag_q-youtube_2}{tag_q-vimeo_2}{tag_q-image_2_value}", "{tag_q-next-question_2}", "CAT_Custom_19", "CAT_Custom_20", "CAT_Custom_22", "CAT_Custom_23", "CAT_Custom_24", "CAT_Custom_25", "CAT_Custom_21", "CAT_Custom_26", "CAT_Custom_27", "CAT_Custom_28", "CAT_Custom_29");
question[3] = new Question("3", "{tag_q-question_3}", "{tag_q-answer-type_3}", "{tag_q-text-answer_301}", "{tag_q-text-answer_302}", "{tag_q-text-answer_303}", "{tag_q-text-answer_304}", "{tag_q-multichoice-answer_3}{tag_q-t/f-answer_3}", "{tag_q-visual-reference_3}", "{tag_q-youtube_3}{tag_q-vimeo_3}{tag_q-image_3_value}", "{tag_q-next-question_3}", "CAT_Custom_30", "CAT_Custom_31", "CAT_Custom_33", "CAT_Custom_34", "CAT_Custom_35", "CAT_Custom_36", "CAT_Custom_32", "CAT_Custom_37", "CAT_Custom_38", "CAT_Custom_39", "CAT_Custom_40");

for (var i = 1; i <= 3; i++) {
    if (question[i].nextQ === "Yes") {
        question[i].createQuestion();
    } else {
        question[1].createQuestion();
    };
}