springboot中使用templates 根据选择树结构id 动态查询 数据 并赋值到input中

需求  动态根据选择的题库id 查询题库数量 动态赋值给input 限制出题数量

 

# 树结构数据展示题库

<div class="form-group">
     <label class="col-sm-3 control-label">题型:</label>
     <div class="col-sm-8">
       <input name="questionName" onclick="selectTree()" id="treeName" type="text" placeholder="请选择题型" class="form-control" required autocomplete="off">
     </div>
</div>

#需要赋值的input框

<div class="form-group">
        <label class="col-sm-3 control-label">单选题数量:</label>
        <div class="col-sm-8">
          <input name="singleChoiceNum" class="form-control" type="number" min = 0 autocomplete="off" id="singleChoiceNum">
        </div>
</div>
<div class="form-group">
       <label class="col-sm-3 control-label">多选题数量:</label>
       <div class="col-sm-8">
         <input name="multipleChoiceNum" class="form-control" type="number" min = 0 autocomplete="off" id="multipleChoiceNum">
       </div>
</div>

 

#获取树结构数据信息

function selectTree() {
            var treeId = $("#treeId").val();
            var questionType = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "exam/question/selectQuestionTree/" + questionType;
            var options = {
                title: '选择题型',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                var questionType = $("input[name='questionType']").val();
          #根据选择的树结构数据,进行异步查询题库单选多选数量
if(questionType != ''){ $.ajax({ //请求方式 type : "POST", //请求的媒体类型 contentType: "application/json;charset=UTF-8", //请求地址 url : ctx + "exam/question/findQuestionSum/?questionType="+questionType, //请求成功 success : function(result) {                  #根据后台查询单选题数量进行赋值 document.getElementById('singleChoiceNum').max = result.examQuestionType.singleChoiceSum;
                 #根据后台查询多选题数量进行赋值 document.getElementById(
'multipleChoiceNum').max = result.examQuestionType.multipleChoiceSum; }, //请求失败,包含具体的错误信息 error : function(e){ console.log(e.status); console.log(e.responseText); } }); } layer.close(index); } }

 #后台代码

@PostMapping("/findQuestionSum")
    @ResponseBody
    public Map<String,Object> findQuestionSum(ExamQuestionType examQuestionType) {

        examQuestionType.setSum1("0");
        ExamQuestionType findsingleChoiceSum = examQuestionTypeService.findsingleChoiceSum(examQuestionType);
        examQuestionType.setSum1("1");
        ExamQuestionType findmultipleChoiceSum = examQuestionTypeService.findsingleChoiceSum(examQuestionType);

        examQuestionType.setSingleChoiceSum(findsingleChoiceSum.getSum1());
        examQuestionType.setMultipleChoiceSum(findmultipleChoiceSum.getSum1());
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("examQuestionType",examQuestionType);


        return map;
    }

 

posted @ 2021-01-25 12:47  ypr-  阅读(517)  评论(0编辑  收藏  举报