You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过DLGIdentifier实现复选框控制对应输入框的启用状态

解决方案

问题根因

你编写的控制逻辑没有问题,复选框取值也正常,状态修改不生效的核心原因是 Digital Micrograph 的 UIFrame 框架不会自动将 UI 属性的修改同步到界面显示,需要手动触发界面刷新。

修复方法

只需要在 SelectAction 方法的循环逻辑结束后,添加 self.UpdateWindow() 语句强制刷新对话框界面即可。
修改后的完整代码如下:

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++){
            DLGEnabled(self.LookupElement("num2_"+(i+1)),self.LookupElement("cb_"+(i+1)).DLGGetValue())
            result(i+":"+self.LookupElement("cb_"+(i+1)).DLGGetValue()+"\n")
        };
        // 新增下面这行刷新UI
        self.UpdateWindow()
    };
    
    TagGroup InputGenerator(object self, number i){
        TagGroup tgBox = DLGCreateBox("Box_"+(i+1))
        
        TagGroup tgLable = DLGCreateLabel("#")
        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++){
            TagGroup item=self.InputGenerator(j)
            main.DLGAddElement(item)
        };
        self.init(main).Display("TestUI")
    };
};

{
    alloc(TestUI).CreateDialog()
};

内容的提问来源于stack exchange,提问作者Renfong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 20:45:00