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

Webix开发:如何将state变量传入.show()弹出窗口?

解决方案

Webix本身没有直接的.show(state)方法,但可以通过以下几种简单方式实现将state传入弹窗,并在Delete按钮点击时调用myFunction(state):

方法1:给弹窗实例挂载自定义属性

在调用弹窗的show()方法前,将state直接赋值给弹窗实例的自定义属性,后续在弹窗内部通过实例获取该属性即可:

修改后的完整代码:

$$('TLVab').attachEvent("onAfterEditStop", function(state, editor, ignoreUpdate) {
    const popup = $$('deleteLTMPopup');
    popup.currentState = state; // 将state挂载到弹窗实例
    popup.show();      
});

UI.deleteLTMPopup= {
    id:'deleteLTMPopup',
    view:'window',
    head:'D',
    modal:true,
    position:'center',
    resize:true,
    move:true,
    autowidth:true,
    body: {
        rows:[
            {id:'delLifeTimeMCN',template:'W'},
            {cols:[
                {},
                {view:'button',value:'Cancel',width:60,click:function(){ 
                    this.getTopParentView().hide()
                }},
                {id:'deleteLTMBtnOK',view:'button',value:'Delete',width:60,click:function(){
                    const popup = this.getTopParentView();
                    myFunction(popup.currentState); // 获取存储的state
                    popup.hide();
                }},
            ]},
        ]
    }
};

方法2:利用弹窗的onShow事件接收参数

给弹窗添加onShow事件回调,调用show()时直接传入state作为参数,在回调中完成state的存储:

修改后的完整代码:

$$('TLVab').attachEvent("onAfterEditStop", function(state, editor, ignoreUpdate) {
    $$('deleteLTMPopup').show(state); // 传入state作为show方法的参数
});

UI.deleteLTMPopup= {
    id:'deleteLTMPopup',
    view:'window',
    head:'D',
    modal:true,
    position:'center',
    resize:true,
    move:true,
    autowidth:true,
    onShow:function(state) { // 接收传入的state
        this.currentState = state;
    },
    body: {
        rows:[
            {id:'delLifeTimeMCN',template:'W'},
            {cols:[
                {},
                {view:'button',value:'Cancel',width:60,click:function(){ 
                    this.getTopParentView().hide()
                }},
                {id:'deleteLTMBtnOK',view:'button',value:'Delete',width:60,click:function(){
                    const popup = this.getTopParentView();
                    myFunction(popup.currentState);
                    popup.hide();
                }},
            ]},
        ]
    }
};

注意事项

  • 两种方法都依赖Webix组件实例可挂载自定义属性的特性,不会破坏组件原有功能。
  • 若弹窗会被多次触发,每次调用show()前都要重新赋值state,避免残留旧数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 11:45:19