最终实现第一个combobox选择后第二个combobox的数据源会实时变化
$('#ListEquStop').datagrid('selectRow', index)
.datagrid('beginEdit', index);
var ed = $('#ListEquStop').datagrid('getEditor', { index: index, field: field });
if (ed) {
($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
var ed1 = $('#ListEquStop').datagrid('getEditor', { index: index, field: 'EquStopTy' });
var ed2 = $('#ListEquStop').datagrid('getEditor', { index: index, field: 'EquStopId' });
//var editor1 = ed[0];
//var editor2 = ed[1];
//var editor3 = ed[2];
$(ed1.target).combobox({
onChange: function (newValue, oldValue) {
$.ajax({
type: 'post',
url: "/DMS/ProductionData/GetListByEquTy",
data: { newValue: newValue },
async: false,
success: function (data) {
$.each(data, function (i, item) {
var id = item.Id;
var desc = item.EquStop_Desc
//alert(id);
//alert(desc);
## _**此处数据已取出,需进行绑定**_
});
}
});
}
});
}
下面是界面部分
{
field: 'EquStopTy', title: '设备停止类型', width: 80, formatter: function (value, row) {
return row.EquStop_Type;
}, editor: {
type: 'combobox',
options: {
url: '/DMS/EquStop/GetComboxDataByEquStopId',
valueField: 'Id',
textField: 'Name',
method: 'post',
//required: true,
//missingMessage: '设备停止项目必选!',
editable: false
}
}
},
{
field: 'EquStopId', title: '设备停止项目', width: 80, formatter: function (value, row) {
return row.EquStop_Desc;
}, editor: {
type: 'combobox',
options: {
url: '/DMS/EquStop/GetComboxDataByEquStop',
valueField: 'Id',
textField: 'Name',
method: 'post',
editable:false
}
}
}
就是说我的desc如何绑定到第二个combobox上
public ActionResult GetListByEquTy(string newValue)
{
List<DMS_EquStopModel> list = new List<DMS_EquStopModel>();
MyCommonHelp mycommonHelp = new MyCommonHelp();
StringBuilder sql = new StringBuilder();
sql.AppendFormat(@"select Id,EquStop_Desc as Name from DMS_EquStop
where EquStop_Type = '{0}'", newValue);
DataTable dt = DBHelp.GetDataTable(sql.ToString());
list = mycommonHelp.ConvertToList<DMS_EquStopModel>(dt);
return Json(list, JsonRequestBehavior.AllowGet);
}