日期:2014-05-16  浏览次数:20379 次

extjs 不同组件,调用方法Ext.getCmp('id');

JScript code

//这里是一个绑定在grid双击事件上的一些代码,问题:这样大量使用id会不会有bug呢?好像有看到说尽量少用id这样的说法
this.homePageConfigGrid.on('rowclick', function(grid, rowIndex, event) {
                    var record = grid.getStore().getAt(rowIndex);
                    me.homePageConfigForm.getForm().loadRecord(record);
                    me.homePageConfigForm.buttons[0].setText('修改');
                    
                    var _flagId = record.get('flag');
                    
                    if( _flagId == '1' ){
                        Ext.getCmp('flag1').checked = true;
                    } else if( _flagId == '2' ){
                        Ext.getCmp('flag7').checked = true;
                    } else if(_flagId == '3'){
                        Ext.getCmp('flag3').checked = true;
                    } else if(_flagId == '4'){
                        Ext.getCmp('flag4').checked = true;
                    } else if(_flagId == '5'){
                        Ext.getCmp('flag5').checked = true;
                    } else if(_flagId == '6'){
                        Ext.getCmp('flag6').checked = true;
                    };
                    
                });
-------------------------------------------------------
//这里是form里央的那个单选框,有7种不同的选项
{
                                xtype : 'fieldset',
                                checkboxToggle : true,
                                hideLabels : true,
                                autoHeight : true,
                                defaultType : 'radio',
                                title : '选择模块',
                                items : [{
                                            boxLabel : '顶部广告',
                                            id : 'flag1',
                                            name : 'flag',
                                            inputValue : '1'
                                        }, {
                                            boxLabel : '右上角广告',
                                            id : 'flag7',
                                            name : 'flag',
                                            inputValue : '7'
                                        }, {
                                            boxLabel : '幻灯片',
                                            id : 'flag2',
                                            name : 'flag',
                                            inputValue : '2'
                                        }, {
                                            boxLabel : '推荐电影',
                                            id : 'flag3',
                                            name : 'flag',
                                            inputValue : '3'
                                        }, {
                                            boxLabel : '活动图片',
                                            id : 'flag4',
                                            name : 'flag',
                                            inputValue : '4'
                                        }, {
                                            boxLabel : '团购图片',
                                            id : 'flag5',
                                            name : 'flag',
                                            inputValue : '5'
                                        }, {
                                            boxLabel : '影评',
                                            id : 'flag6',
                                            name : 'flag',
                                            inputValue : '6'
                                        }]
                            }




求大牛们看看,提点建议,如果不用id这种方式用其他的什么方式比较好,简单一点最好,


------解决方案--------------------
首先,没有要少使用id这回事
别人这样和你说主要是因为大量配置id可能一不小心就重复了,不配置id可以由