流程: 1.下拉框选择后,提交表单 在提交中将选择的值设置到sessionStorage 2.使用form.val和form.render()
<div class="layui-inline">
<label class="layui-form-label">年级</label>
<div class="layui-input-inline">
<select name="grade" lay-search id="form_view_grade" lay-search>
<script id="form_tpl_grade" type="text/html">
<option value=""></option>
{{# var targetdic = getAlldic(0); for (var i = 0; i < targetdic.length; i++) { }}
<option value=" {{targetdic[i].code}}">
{{targetdic[i].codename}}
</option>
{{# } }}
</script>
</select>
</div>
</div>
form.on('submit(data-search-btn)', function (data) {
console.log(data.field);
sessionStorage.setItem('gradeValue', JSON.stringify(data.field.grade));
sessionStorage.setItem('subjectValue', JSON.stringify(data.field.subject));
sessionStorage.setItem('semesterValue', JSON.stringify(data.field.semester));
}
form.render('select');
form.val("filter", {
"grade": JSON.parse(sessionStorage.getItem('gradeValue')),
"subject": JSON.parse(sessionStorage.getItem('subjectValue')),
"semester": JSON.parse(sessionStorage.getItem('semesterValue')),
});
var data1 = form.val("filter");
console.log(data1);
|