layui 下拉多选xm-select的赋值问题
html:
<div id="xmselectfrequency_id" class="xm-select-demo" style="width:168px;"></div>
js:
$.ajax({
url:url+ '/data/demoXmselect',
data:{
code: "Dtz_code",// 配置步骤:配置SQL动态值数据源
conditions: ids
},
async: false,
type: 'post',
success: function (result) {
ResData = result.data;
xmSelect.render({
el: '#xmselectfrequency_id',
toolbar:{
show: true,
},
autoRow: true,
data:ResData
})
}
})
其中ResData=result.date为.下拉选项是这些数据
[
{ "name": "name1","value": "1"},
{"name": "name2","value": "848552487844577368" },
{"name": "name3", "value": "848599489450082393" },
{"name": "name4", "value": "853662471347503147" }
]
以下是修改时候的代码
if(id != "")
{
$.ajax({
url:url ,
data:{
code: "fnsg",// 配置步骤:配置SQL动态值数据源
conditions: ids
},
async: false,
type: 'post',
success: function (result) {
debugger
ResData = result.data;
// 控制台中result.data[0].frequency_id的值--- "843471547225079872,797795515503739878"
var frequency_id = [];
frequency_id=result.data[0].frequency_id
$.ajax({
url:url + '/demo1',
data:{
code: "attendance",// 配置步骤:配置SQL动态值数据源
// conditions: ids
},
async: false,
type: 'post',
success: function (result) {
debugger
ResData = result.data;
xmSelect.render({
el: '#xmselectfrequency_id',
initValue: frequency_id,
toolbar:{
show: true,
},
autoRow: true,
data:ResData
})
},
error:function(result){
layer.msg('失败', {icon: 1, title: '提示'});
}
});
是想问如何给xm-select设置默认值吗?
initValue 的值是包含 data 中 value 的数组,看看对应上没有。
由于没有完整的代码以及具体的问题描述,我无法确定您尝试了哪些赋值方法,并不能给出具体的解决方案。建议您检查一下您的代码,或者向社区提问以获得更详细的帮助。