$("#fieldValue").combobox("loadData", dataList);
时间: 2023-12-29 09:04:10 浏览: 35
这是一个 jQuery 的代码片段,用于将数据加载到下拉框中。其中,`$("#fieldValue")` 是选择器,选择了一个 id 为 "fieldValue" 的元素,这个元素应该是一个下拉框。`.combobox("loadData", dataList)` 是调用了 `combobox` 插件的 `loadData` 方法,并将 `dataList` 作为参数传入,用于加载数据到下拉框中。`dataList` 应该是一个数组,包含了要加载到下拉框中的数据。
相关问题
.combobox("loadData"怎么用
`.combobox("loadData")` 方法可以用于动态加载数据到 `combobox` 组件中。您可以使用以下示例代码来了解如何使用该方法:
```javascript
// 初始化combobox
$('#combobox').combobox({
valueField: 'id',
textField: 'text'
});
// 动态加载数据
$('#loadBtn').click(function() {
var newData = [{
id: '4',
text: 'Option 4'
}, {
id: '5',
text: 'Option 5'
}, {
id: '6',
text: 'Option 6'
}];
$('#combobox').combobox('loadData', newData);
});
```
在上述代码中,首先使用 `valueField` 和 `textField` 属性初始化了一个空的 `combobox`。然后,在点击按钮触发的 `click` 事件中,创建了一个新的数据数组 `newData`,其中包含要加载到下拉框中的选项。最后,通过调用 `.combobox('loadData', newData)` 方法将新的数据加载到 `combobox` 中。
请注意,上述代码中的 `#combobox` 和 `#loadBtn` 是相应 HTML 元素的选择器,请根据实际情况进行修改。此外,您还可以根据需要调整其他配置选项和样式。
使用 `.combobox("loadData")` 方法可以在运行时动态更新 `combobox` 的选项数据,在需要更新选项时非常有用。
{field: 'commodityConfig', width:250,title:"配置", editor: { type:'combobox', options: { valueField: 'config_name', textField: 'config_name', url: 'getOtherColumnValue.php?columnValue=' + $('#dg').datagrid('getEditor', {index:editIndex,field:'otherColumn'}).target.val(), onChange: function(newValue, oldValue) { var editor = $(this).combobox('options').editor; var row = editor.getRow(editor.target.closest('tr')); var otherColumnValue = row.otherColumn; $(this).combobox('reload', 'getOtherColumnValue.php?columnValue=' + otherColumnValue); } } } }如何获取当前index
在 easyui 的 datagrid 中,可以使用 `onBeforeEdit` 事件获取当前正在编辑的行的索引,然后在 `options` 中引用该索引即可。具体实现如下:
```
$('#dg').datagrid({
onBeforeEdit: function(index, row) {
// 将当前编辑行的索引保存到全局变量 editIndex 中
editIndex = index;
},
columns: [
{
field: 'commodityConfig',
width: 250,
title: '配置',
editor: {
type: 'combobox',
options: {
valueField: 'config_name',
textField: 'config_name',
url: 'getOtherColumnValue.php?columnValue=' + $('#dg').datagrid('getEditor', {index: editIndex, field: 'otherColumn'}).target.val(),
onChange: function(newValue, oldValue) {
// 在 onChange 事件中使用 editIndex 引用当前编辑行的索引
var editor = $(this).combobox('options').editor;
var row = editor.getRow(editor.target.closest('tr'));
var otherColumnValue = row.otherColumn;
$(this).combobox('reload', 'getOtherColumnValue.php?columnValue=' + otherColumnValue);
}
}
}
},
// 其他列
]
});
```
在上面的代码中,我们在 `onBeforeEdit` 事件中将当前编辑行的索引保存到全局变量 `editIndex` 中,然后在 `options` 中引用该变量即可。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)