龙空技术网

初始化下拉列表select

在水一方357159258 200

前言:

今天兄弟们对“jquerycxselect”大概比较关切,大家都想要分析一些“jquerycxselect”的相关文章。那么小编在网摘上汇集了一些关于“jquerycxselect””的相关文章,希望大家能喜欢,兄弟们一起来了解一下吧!

初始化下拉列表select,后台返回的数据为

[{"dwtype":"pinzhong","name":"徐香","id":"1"},{"dwtype":"pinzhong","name":"翠香","id":"2"}]

1,thymeleaf设置

<select name="type1" id="type1" lay-verify="required"  lay-filter="democity"><option value=""></option><option th:each="wptype1 : ${application.wptype}" 	th:value="${wptype1.id}" th:text="${wptype1.name}"	th:selected="${wptype1.id} == ${wupin.type1}"> //选中下拉列表的某一项</option></select>

2,jquery设置

$.ajax({            url: '/wptype1',            dataType: 'json',            type: 'get',            success: function (data)            {                //alert(data);                $.each(data, function (index, item)                {                    $('#type1').append(new Option(item.id+"_"+item.name, item.id));                  // 下拉菜单里添加元素                });              //选中下拉列表的某一项                $('#type1').val('[[${application.wptype.id}]]');                layui.form.render("select");//重新渲染 固定写法            }        });

2020-02-03

标签: #jquerycxselect