checkbox - 如何从复选框 DLGIdentifier 启用条目?
问题描述
在上一个问题的答案中,我展示了如何在更改复选框状态时启用条目。这一次,我想创建多个由相应复选框控制的条目。
对于每个复选框,我使用 DLGIdentifier 对其进行标记,然后使用 DLGEnabled(self.LookupElement("entryId"), self.LookupElement("cb_ID").DLGGetValue()) 启用/禁用它,但它失败了 QQ 有谁知道如何解决它?先感谢您。
这是我的代码。
class TestUI : UIFrame{
number true, false, n_items
TestUI(object self){
true=1; false=0;
result("TestUI ["+self.ScriptObjectGetID()+"] constructed\n")
};
~TestUI(object self){
result("TestUI ["+self.ScriptObjectGetID()+"] destructed\n")
};
void SelectAction(object self, TagGroup tgItem){
for(number i=0;i<n_items;i++){
// change state, but it failed.
DLGEnabled(self.LookupElement("num2_"+(i+1)),self.LookupElement("cb_"+(i+1)).DLGGetValue())
// the values of each checkbox are retured correctly.
result(i+":"+self.LookupElement("cb_"+(i+1)).DLGGetValue()+"\n")
};
};
TagGroup InputGenerator(object self, number i){
// Entry template
TagGroup tgBox = DLGCreateBox("Box_"+(i+1))
TagGroup tgLable = DLGCreateLabel("#")
// each elements are using DLGIdentifier to label it
TagGroup tgNumber1 = DLGCreateRealField(10,5,0).DLGIdentifier("num1_"+(i+1))
TagGroup tgNumber2 = DLGCreateRealField(10,10,0).DLGIdentifier("num2_"+(i+1))
TagGroup tgGroup = DLGGroupItems(tgLable,tgNumber1,tgNumber2).DLGTableLayout(3,1,0)
tgBox.DLGAddElement(tgGroup)
TagGroup cb = DLGCreateCheckBox("IsCheck", false,"SelectAction").DLGIdentifier("cb_"+(i+1))
tgBox.DLGAddElement(cb)
DLGEnabled(tgNumber2,cb.DLGGetValue())
return tgBox
}
void CreateDialog(object self){
TagGroup main = DLGCreateDialog("Test")
n_items = 3
for (number j=0; j<n_items; j++){
//create multiple entries by for loop
TagGroup item=self.InputGenerator(j)
main.DLGAddElement(item)
};
self.init(main).Display("TestUI")
};
};
{
alloc(TestUI).CreateDialog()
};
解决方案
您可能希望将SelectAction方法替换为以下内容:
void SelectAction(object self, TagGroup tgItem){
// tgItem is the taggroup of the element that fired the action
// so no for-loop for checking all is needed here.
// tgItem.TagGroupOpenBrowserWindow("",0)
number checked = tgItem.DLGGetValue()
string IDcheck
if (!tgItem.DLGGetIdentifier(IDcheck)) return
string IDField = "num2_" + right( IDcheck, len(IDcheck)-3 )
// The DLGEnable() command only changes the taggroup of the dialog
// but doesn't do anything with the dialog window itself.
// There is a separate command to enable/disable an element of the dialog.
// void SetElementIsEnabled( ScriptObject dialogUI, String item_identifier, Boolean is_enabled )
self.SetElementIsEnabled(IDField ,checked)
return
};
本质上,您需要不同的命令来更改显示的对话框。它已记录在案,但有点难以找到:
推荐阅读
- pipenv - "pipenv 安装 --system" == "pip 安装"
- angular - 模板驱动表单的角度自定义交叉字段验证器
- java - JPA 规范连接许多表
- javascript - Office js (Word) : addFromNamedItemAsync 函数的参数不正确
- javascript - 原始 html 中的指令属性在 Angular 8 应用程序中不起作用
- r - 我想在以列名作为变量的闪亮模块中使用内连接函数
- javascript - 我可以在javascript中的任何地方使用异步函数吗?
- python - 超过了 runtime:python 的语言工作者重新启动重试次数。关闭并主动回收 Functions Host 以恢复
- powershell - 多维数组的 Foreach 循环问题
- python - Xlwings expand() 函数跳过空单元格的行