ITOO学生端—动态拼接试卷(2)

接着上篇博客!

        拼接完题干之后,通过 试题类的id去查询该类型下的小题。同时把大题干,和试卷的描述传过去(干嘛使,不知道!)

htmlType = queryComponent(
<span style="white-space:pre">	</span>htmlType,
<span style="white-space:pre">	</span>questionTypeId,
<span style="white-space:pre">	</span>paperDetailList[i].lstQuestionMain);

调用queryComponent方法()

//根据题型,查询组件信息
	function queryComponent(htmlType, questionTypeId, questionMainList) {

		var htmlCourse = "";
		var b;
		$.ajax({
			type : "POST",
			async : false,
			dataType : "text",
			url : "${pageContext.request.contextPath}/queryComponent?questionTypeId="
			  + questionTypeId,
			success : function(data) {
			var componentList = eval(data);
			htmlType = onlineEdit(htmlType, componentList,
				questionMainList, questionTypeId);
					}
				});
		return htmlType;
	}

查询出小提信息之后调用 onlineEdit方法()


//根据试题拼接组件
	function onlineEdit(htmlType, componentList, questionMainList,
			questionTypeId) {
		for (var j = 0; j < questionMainList.length; j++) {

			for (var i = 0; i < componentList.length; i++) {
				var unit = eval(componentList[i]);
				var questionContent = "";
				switch (unit.field) {
				//大题干
				case "bigTGTag":
					questionContent = questionMainList[j].questionContent;
					if (questionContent == null) {
						questionContent = " ";
					}
					//大小题型的大题干
					if (questionMainList[j].isParentQuestion == 1) {
						htmlType += "</div>";
						htmlType += "<div class='itoo-question' id='"+questionMainList[j].id+"'>"
								+ "<br>";
						htmlType += "<div class='questionRequire' name='questionContent' "+ "value=''>"
								+ (questionMainList[j].typeOrder + 1)
								+ "、"
								+ questionContent + "</div>";

						//不区分大小题型
					} else if (questionMainList[j].isParentQuestion == 0
					&& (questionMainList[j].parentQuestionId == "" || questionMainList[j].parentQuestionId == null)) {
						htmlType += "<div class='itoo-question' id='"+questionMainList[j].id+"'>"
								+ "<br>";
						htmlType += "<div class='questionRequire' name='questionContent' "+ "value=''>"
								+ (questionMainList[j].typeOrder + 1)
								+ "、"
								+ questionContent + "</div>";
					}

					break;

				//选项
				case "optionTag":
					var optionLength = questionMainList[j].options.length;
					if (optionLength != 0) {
						for (var count = 0; count < questionMainList[j].options.length; count++) {
							optionContent = questionMainList[j].options[count].optionsContent;
							if (optionContent == null) {
								optionContent == "";
							}
							var questionId = questionMainList[j].id;
							var id = questionMainList[j].options[count].id;

							var studentAnswer = getNumber(count);

							htmlType += "<div id='"
									+ questionMainList[j].options[count].id
									+ "' class='optionBox' onclick='submitId(this,""
									+ questionMainList[j].answer
									+ "",""
									+ questionMainList[j].score
									+ "","" + studentAnswer
									+ """ + ")' value='" + questionId;
						htmlType += "'><label class='optionBox'><input  type='radio' value='0' name='option"
									+ j + questionTypeId;
							if (questionMainList[j].studentAnswer == questionMainList[j].options[count].id) {
								htmlType += "' checked>";
							} else {
								htmlType += "'>";
							}

							htmlType += " " + getNumber(count) + "、"
									+ optionContent + "</input></label></div>";

						}

						htmlType += "</div>";

					}

					break;

				//小题干
				case "littleTGTag":

					if (questionMainList[j].isParentQuestion == 0
							&& questionMainList[j].parentQuestionId != "") {
						questionContent = questionMainList[j].questionContent;
						htmlType += "<div class='itoo-question' id='"+questionMainList[j].id+"'>";
			                        htmlType += "<div id='"+questionMainList[j].id+"' class='questionRequire' name='questionContent' "+ "value=''>"
								+ "("
								+ (questionMainList[j].typeOrder + 1)
								+ ")" + "、" + questionContent + "</div>";
					}

					break;

				//填空题
				case "fillLineTag":

					htmlType += "<textarea id='"
							+ questionMainList[j].id
							+ "' class='fillLineText' onclick='submitId(this)' value='' ></textarea><br>";
					htmlType += "</div>";
					break;

				case "answerTextTag":
					var answerTextTagID = questionMainList[j].id;
					var answerScore = questionMainList[j].score;
					var answerCount = j;

					htmlType += "<input id='"
							+ "answer"
							+ answerCount
							+ "' class='areaText' onblur='blurEvent(this,""
							+ answerTextTagID + "","" + answerScore
							+ """
							+ ")' type='text' value='enter'></input><br></div>";

					break;

				}

			}

		}
		htmlType += "</div>";

		return htmlType;
	}

          通过一个星期对ITOO学生端的维护,对其中的需求和代码算是有了点了解,也增加了自己对java的信心,这次总结只是对代码的调用和逻辑进行解释。日后通过深入的学习,了解些里面的原理,然后再次总结。在代码走查的时候听师哥、师姐说什么远程调用、APO容器、日志等技术,这次我们都要使用和学习了,期待,同志们加油了!

你可能感兴趣的:(ITOO学生端—动态拼接试卷(2))