combobox当editor关闭后下拉款无值
时间: 2023-09-12 10:05:16 浏览: 24
可能是因为在关闭editor之前没有正确地设置combobox的数据源。请确保在设置editor的同时,也正确地设置了combobox的数据源。另外,还需要检查数据源是否为空。如果数据源为空,下拉框将不会显示任何值。你可以尝试在editor打开之前重新加载combobox的数据源。如果问题仍然存在,请提供更多的代码或细节,以便我更好地帮助你解决问题。
相关问题
combobox当editor关闭后下拉款为什么无值
当combobox的editor关闭后,下拉框中没有值可能是因为在关闭editor之前未正确设置combobox的数据源或者数据源为空。此外,还可能是因为combobox的显示文本字段或值字段未正确设置。
要解决此问题,你可以检查以下几个方面:
1. 确认在打开editor之前正确设置了combobox的数据源。
2. 检查数据源是否为空,如果为空,则下拉框将不会显示任何值。
3. 确认combobox的显示文本字段和值字段已正确设置。如果这两个字段未正确设置,下拉框中将不会显示任何值。
如果以上几个方面都已确认无误,但问题仍然存在,你可以提供更多的代码或细节,以便我更好地帮助你解决问题。
datagrid根据datagridid不同加载不同的combobox下拉框并初始化下拉款值
您可以使用`onBeforeLoad`事件来根据`datagrid`的不同`id`值来动态配置不同的`combobox`下拉框,并在`onLoadSuccess`事件中初始化下拉框的值。
具体来说,您可以在`onBeforeLoad`事件中获取`datagrid`的`id`值,并根据不同的`id`值来动态配置不同的`combobox`下拉框。例如:
```
$('#myDatagrid1').datagrid({
url: 'data1.json',
columns: [[
{field: 'id', title: 'ID', width: 100},
{field: 'name', title: '名称', width: 100},
{field: 'type', title: '类型', width: 100}
]],
onBeforeLoad: function (params) {
// 获取datagrid的id值
var datagridId = $(this).attr('id');
// 根据不同的id值配置不同的下拉框选项
if (datagridId == 'myDatagrid1') {
$('#myDatagrid1').datagrid('getColumnOption', 'type').editor = {
type: 'combobox',
options: {
valueField: 'id',
textField: 'text',
data: [{id:1,text:'选项一'},{id:2,text:'选项二'},{id:3,text:'选项三'}]
}
};
} else if (datagridId == 'myDatagrid2') {
$('#myDatagrid2').datagrid('getColumnOption', 'type').editor = {
type: 'combobox',
options: {
valueField: 'id',
textField: 'text',
data: [{id:4,text:'选项四'},{id:5,text:'选项五'},{id:6,text:'选项六'}]
}
};
}
},
onLoadSuccess: function (data) {
// 初始化下拉框的值
var rows = $('#myDatagrid1').datagrid('getRows');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var type = row.type;
var $combobox = $('#myDatagrid1').datagrid('getEditor', {index:i,field:'type'}).target;
$combobox.combobox('setValue', type);
}
}
});
$('#myDatagrid2').datagrid({
url: 'data2.json',
columns: [[
{field: 'id', title: 'ID', width: 100},
{field: 'name', title: '名称', width: 100},
{field: 'type', title: '类型', width: 100}
]],
onBeforeLoad: function (params) {
// 获取datagrid的id值
var datagridId = $(this).attr('id');
// 根据不同的id值配置不同的下拉框选项
if (datagridId == 'myDatagrid1') {
$('#myDatagrid1').datagrid('getColumnOption', 'type').editor = {
type: 'combobox',
options: {
valueField: 'id',
textField: 'text',
data: [{id:1,text:'选项一'},{id:2,text:'选项二'},{id:3,text:'选项三'}]
}
};
} else if (datagridId == 'myDatagrid2') {
$('#myDatagrid2').datagrid('getColumnOption', 'type').editor = {
type: 'combobox',
options: {
valueField: 'id',
textField: 'text',
data: [{id:4,text:'选项四'},{id:5,text:'选项五'},{id:6,text:'选项六'}]
}
};
}
},
onLoadSuccess: function (data) {
// 初始化下拉框的值
var rows = $('#myDatagrid2').datagrid('getRows');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var type = row.type;
var $combobox = $('#myDatagrid2').datagrid('getEditor', {index:i,field:'type'}).target;
$combobox.combobox('setValue', type);
}
}
});
```
在上面的代码中,我们分别创建了两个`datagrid`,并在它们的`onBeforeLoad`事件中根据不同的`id`值动态配置不同的`combobox`下拉框。在`onLoadSuccess`事件中,我们使用`datagrid`的`getEditor`方法来获取相应的下拉框,并使用`setValue`方法来设置下拉框的值。
需要注意的是,在使用`getEditor`方法获取下拉框时,需要将`field`属性设置为'type',因为'type'是下拉框所在的列名。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)