Javascript 单击一个按钮即可编辑Extjs

Javascript 单击一个按钮即可编辑Extjs,javascript,extjs,Javascript,Extjs,我在网格的每一行上都有“激活”按钮,因此用户只能激活他们要编辑的行,并且按钮更改为“停用”。我如何保存按钮的状态以备下次重新打开面板时使用?以下是我的代码,也是: 激活/停用按钮的代码: function extjsRenderer(val,meta,rec) { var id = Ext.id(); Ext.defer(function () { Ext.widget('button', { re

我在网格的每一行上都有“激活”按钮,因此用户只能激活他们要编辑的行,并且按钮更改为“停用”。我如何保存按钮的状态以备下次重新打开面板时使用?以下是我的代码,也是:

激活/停用按钮的代码:

    function extjsRenderer(val,meta,rec) {        
    var id = Ext.id();
    Ext.defer(function () {

            Ext.widget('button', {
                renderTo: id,
                id:'editButton_' + rec.get('id'),
                text: 'Activate',
                width: 75,

        handler: function() {
            if (this.active == null || this.active == false) {
                this.active = true
                this.setText('Deactivate');
                return;
            }

            if (this.active == true) {
                this.active = false;
                this.setText('Activate');
                return;
            }
        }
            });
    //    } 
    }, 50);
    return Ext.String.format('<div id="{0}"></div>', id);
}
}
});
函数extjsRenderer(val,meta,rec){
var id=Ext.id();
Ext.defer(函数(){
Ext.widget('按钮'{
renderTo:id,
id:'editButton_u'+rec.get('id'),
文本:“激活”,
宽度:75,
处理程序:函数(){
if(this.active==null | | this.active==false){
this.active=true
this.setText('Deactivate');
返回;
}
如果(this.active==true){
this.active=false;
this.setText('Activate');
返回;
}
}
});
//    } 
}, 50);
返回Ext.String.format(“”,id);
}
}
});

这相当简单。我为你做了一把小小提琴:


ExtJS组件的工作方式类似于简单的对象文字,因此您可以使用任何您想要的方式对其进行扩展。在本例中,我添加了属性“active”,可以在beforeEdit侦听器中进行检查。

非常感谢您的帮助。我实际上修改了你的代码,因为我需要每行的按钮也将行编辑更改为单元格编辑,但它不能正常工作,你能检查它并提供帮助吗?看看我上面的链接小提琴。每个按钮都需要一个唯一的id。我在json中添加了一个id属性来标识哪一行可以编辑。非常感谢,它成功了!我只需要保存状态。目前,当我重新打开面板时,所有按钮都会重置为激活状态。因此,如果在下次保存之前激活了它,您可以使用属性(例如“activeedit”)将激活状态存储在存储中,并检查存储的状态。从按钮中删除activate属性,并用
record.set('activeedit,true)
编辑storeitem;我又更新了小提琴。。。
    function extjsRenderer(val,meta,rec) {        
    var id = Ext.id();
    Ext.defer(function () {

            Ext.widget('button', {
                renderTo: id,
                id:'editButton_' + rec.get('id'),
                text: 'Activate',
                width: 75,

        handler: function() {
            if (this.active == null || this.active == false) {
                this.active = true
                this.setText('Deactivate');
                return;
            }

            if (this.active == true) {
                this.active = false;
                this.setText('Activate');
                return;
            }
        }
            });
    //    } 
    }, 50);
    return Ext.String.format('<div id="{0}"></div>', id);
}
}
});