下拉列表联动处理(Python实现)
先说下需求:
# 设置了两个下拉列表,怎样做到一个下拉列表控制另一个下拉列表呢?
# 例如第一个下拉列表内容为ABCD,第二个下拉列表为A1、A2、A3、B1、B2、B3、C1、C2、C3、D1、D2、D3,怎样做到第一个下拉列表选择A的时候,再选第二个下拉列表只显示A1、A2、A3呢?
实现思路:
1、重写OnInitialize事件,动态绑定两个下拉框的数据
2、重写DataChanged事件,根据第一个下拉框的选中值,动态加载填充第二个下拉框的值
import clr clr.AddReference("Kingdee.BOS") from Kingdee.BOS import LocaleValue from Kingdee.BOS.Core.Metadata import EnumItem from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import ComboFieldEditor from System.Collections.Generic import * from System import StringComparison def OnInitialize(e): array1 = ["A", "B", "C", "D"] newList = List[EnumItem]() seq = 0 for item in array1: newItem = EnumItem() newItem.Seq = seq newItem.Value = item newItem.Caption = LocaleValue(item, this.View.Context.UserLocale.LCID) newList.Add(newItem) seq = seq + 1 #获取fieldEditor来设置下拉的选项列表 fieldEditor = this.View.GetControl("FCombo1") fieldEditor.SetComboItems(newList) newList2 = List[EnumItem]() seq = 0 dict = {'A': ['A1', 'A2', 'A3'], 'B': ['B1', 'B2', 'B3'], 'C': ['C1', 'C2', 'C3'], 'D': ['D1', 'D2', 'D3']} for item in dict['A']: newItem = EnumItem() newItem.Seq = seq newItem.Value = item newItem.Caption = LocaleValue(item, this.View.Context.UserLocale.LCID) newList2.Add(newItem) seq = seq + 1 fieldEditor2 = this.View.GetControl("FCombo2") fieldEditor2.SetComboItems(newList2) def DataChanged(e): if e.Field.Key.Equals("FCOMBO1", StringComparison.OrdinalIgnoreCase): combo1Value = this.View.Model.GetValue("FCombo1").ToString() dict = {'A': ['A1', 'A2', 'A3'], 'B': ['B1', 'B2', 'B3'], 'C': ['C1', 'C2', 'C3'], 'D': ['D1', 'D2', 'D3']} array1 = dict[combo1Value] if len(array1) > 0: newList = List[EnumItem]() seq = 0 for item in array1: newItem = EnumItem() newItem.Seq = seq newItem.Value = item newItem.Caption = LocaleValue(item, this.View.Context.UserLocale.LCID) newList.Add(newItem) seq = seq + 1 fieldEditor2 = this.View.GetControl("FCombo2") fieldEditor2.SetComboItems(newList)
public override void OnInitialize(InitializeEventArgs e) { base.OnInitialize(e); //新的枚举列表 List<EnumItem> newList = new List<EnumItem>(); string[] array = { "A", "B", "C", "D" }; for (var i = 0; i < array.Length; i++) { newList.Add(new EnumItem { Seq = i, Value = array[i], Caption = new LocaleValue(array[i], this.Context.UserLocale.LCID) }); } var dic = new Dictionary<string, List<string>> { { "A", new List<string>() { "A1", "A2", "A3"} }, { "B", new List<string>() { "B1", "B2", "B3"} }, { "C", new List<string>() { "C1", "C2", "C3"} }, { "D", new List<string>() { "D1", "D2", "D3"} } }; List<EnumItem> FCombo2 = new List<EnumItem>(); int index = 0; foreach (var item in dic["A"]) { FCombo2.Add(new EnumItem { Seq = index, Value = item, Caption = new LocaleValue(item, this.Context.UserLocale.LCID) }); index++; } //获取fieldEditor来设置下拉的选项列表 ComboFieldEditor fieldEditor = this.View.GetControl<ComboFieldEditor>("FCombo1"); fieldEditor.SetComboItems(newList); ComboFieldEditor fieldEditor2 = this.View.GetControl<ComboFieldEditor>("FCombo2"); fieldEditor2.SetComboItems(FCombo2); } public override void DataChanged(BOS.Core.DynamicForm.PlugIn.Args.DataChangedEventArgs e) { switch (e.Field.Key.ToUpper()) { case "FCOMBO1": var combo1Value = this.View.Model.GetValue("FCombo1").ToString(); var dic = new Dictionary<string, List<string>> { { "A", new List<string>() { "A1", "A2", "A3"} }, { "B", new List<string>() { "B1", "B2", "B3"} }, { "C", new List<string>() { "C1", "C2", "C3"} }, { "D", new List<string>() { "D1", "D2", "D3"} } }; var combo2 = new List<string>(); var result = dic.TryGetValue(combo1Value, out combo2); if (result) { //新的枚举列表 List<EnumItem> newList = new List<EnumItem>(); foreach (var item in combo2) { newList.Add(new EnumItem { Seq = combo2.IndexOf(item), Value = item, Caption = new LocaleValue(item, this.Context.UserLocale.LCID) }); } //获取fieldEditor来设置下拉的选项列表 ComboFieldEditor fieldEditor = this.View.GetControl<ComboFieldEditor>("FCombo2"); fieldEditor.SetComboItems(newList); } break; } }
找了老半天了,终于让俺找到了
联动是可以,但是保存后重新打开,并没有赋值,但是我看后台是存了值的,请问这个怎么处理
列表过滤怎么处理呢?
老师,您好,请教一下,单据里面动态绑定下拉列表了,那么列表根据这个字段过滤的时候,没有选项啊。
下拉列表联动处理(Python实现)
先说下需求:# 设置了两个下拉列表,怎样做到一个下拉列表控制另一个下拉列表呢?# 例如第一个下拉列表内容为ABCD,第二个下拉列表为A1、...
点击下载文档
上一篇:云星空项目管理下一篇:即时库存明细添加物料图片
本文2024-09-16 19:08:47发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-26699.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章