美文网首页aardio
记录aardio中listview配置文件自动加载

记录aardio中listview配置文件自动加载

作者: LCSan | 来源:发表于2023-08-06 11:22 被阅读0次

    winform.bindConfig会自动绑定配置文件保存和加载。其加载过程在执行bindConfig时就调用了config的afterLoad,进行控件赋值。

    bindConfig = function(cfg,fields){
                    ...
                    if(fields){
                        cfg.afterLoad = function(){
                            for(name,ctrl in winform.eachControl() ){
                                var v =  fields[name]  : fields[ctrl.cls]
                                if( v  ) {
                                    if(type(v) == "table"){
                                        for(n,v2 in v){
                                            if( ..string.find(name,n) ) {
                                                fields[name] = v2;
                                                v = v2;
                                                if(cfg[name]!==null){ ctrl[v] = cfg[name];} else {cfg[name]= ctrl[v]};
                                                continue 2;
                                            }
                                        } 
                                        continue;
                                    }
                                    if(cfg[name]!==null){ ctrl[v] = cfg[name];} else {cfg[name]= ctrl[v]};
                                }
                            };
                        }
                        cfg.afterLoad();
                        cfg.save();
                    }
                    ...
                };
    

    listview比较特殊没有设置表头的时候,直接设置items会失效,解决这个先后问题即可。
    1、将listview设置头的代码放在bindConfig前执行

    
    import config;
    
    // 这里必须放在conf前面,因为bingconfig会直接调用afterLoad,而listview没有头的情况下,直接设置items回丢数据。
    winform.listview_task.setColumns({"序号";"任务时间";"任务内容";"物品限制数量"},{50;140;140;140});
    // 开启双缓冲,显示更流畅
    winform.listview_task.enableDoubleBuffering();
    ...
    winform.bindConfig( config.winform,{
        edit = "text";
        radiobutton = "checked";
        checkbox = "checked";
        combobox = "selIndex";
        plus ={
            ["^chk"] = "checked";
            ["^edit"] = "text";
        };
        listbox = "items";
        listview = "items";
    } );
    

    2、在listview设置头后重新加载一遍配置

    import config;
    winform.bindConfig( config.winform,{
        edit = "text";
        radiobutton = "checked";
        checkbox = "checked";
        combobox = "selIndex";
        plus ={
            ["^chk"] = "checked";
            ["^edit"] = "text";
        };
        listbox = "items";
        listview = "items";
    } );
    ...
    // 这里必须放在conf前面,因为bingconfig会直接调用afterLoad,而listview没有头的情况下,直接设置items回丢数据。
    winform.listview_task.setColumns({"序号";"任务时间";"任务内容";"物品限制数量"},{50;140;140;140});
    // 开启双缓冲,显示更流畅
    winform.listview_task.enableDoubleBuffering();
    // 重新加载数据
    config.winform.load()
    

    相关文章

      网友评论

        本文标题:记录aardio中listview配置文件自动加载

        本文链接:https://www.haomeiwen.com/subject/reaipdtx.html