layui select 从数据库获得下拉框数据

<select type="text" class="layui-select" name="express_company" id="express_company_add" lay-filter="express_company" xm-select="xmSelect1">
</select>


// 监听 select 元素的 change 事件
form.on('select(express_company)', function (data) {
	var selectedValue = data.value; // 获取选中的值
	var selectedText = data.elem[data.elem.selectedIndex].text; // 获取选中的文本
});

// 从数据库获得下拉框数据
formSelects.config('xmSelect1', {
	searchUrl: "selectAccountList.action",
	methods: 'post',
	beforeSuccess: function (id, url, searchVal, res) {
		let resultData = [];
		for (let i = 0; i < res.data.length; i++) {
			let temp = []
			temp["name"] = res.data[i].name;
			temp["value"] = res.data[i].value;
			resultData.push(temp)
		}
		return resultData;
	},
});

你可能感兴趣的:(layui,javascript,java)