如何在extjs中打开或关闭开关值

时间:2017-06-20 07:50:16

标签: javascript extjs

当我想在切换开关中获得价值时我有问题,但是我无法获得价值,有多少方式可以获得价值开启或关闭以制造条件

Extjs:      xtype:'容器',                     flex:1,                     参考:'btnPreview',                     itemId:'btnPreview',                     停靠:'底部',

                items: [
                {
                xtype: 'list',
                cls: 'listViewItemExchange',
                itemId: 'AccT24',
                //enableToggle: true,
                html: [


                     ].join('')
                     ,style: [
                        'padding:0% 3%;'
                        ,'background-color:rgba(255, 255, 255, 0.7);'
                        //,'margin:3% 3% 3% 3%;'
                        ,'margin: 0.5em;'
                        ,'border-radius: 6px;'

                    ].join(''),

                     listeners:
                    {

                        element: 'element',
                        delegate: 'div.switch',
                        change: function(el,checked,items){
                            console.info('*el*',el);
                            console.info('*checked*',checked);
                            var items = Ext.DomQuery.select('.toggle');
                            console.log('items',items)
                            var checkeOff = Ext.Viewport.getActiveItem(checked);
                            console.log('checkeOff',checkeOff)
                            var checkeOn = Ext.Viewport.getActiveItem(el);
                            console.log('checkeOn',checkeOn)
                            var enableToggle = el.getValue();
                            console.log('enableToggle',enableToggle)
                            var Ischecked = false;

                                alert('enable',el.items);   // do something
                            }
                            else if (!this.enable){
                               // this.enable(); 
                                console.log('Disenable')
                                 alert('Disenable',el.items);                                // enable togglefield  
                            }

                            var items = Ext.DomQuery.select('.toggle');

                            if(items[0].checked==true)

                            {
                                console.log('if')
                                me.toggle(true,true)

                            }
                            else if(items[0].checked==false)
                            //else()
                            {
                                //('false');
                            }*/
                        },
                          togglechanged : function (newValue) {
                            console.log(newValue)
                            alert('togglechanged')
                        }


                   }

HTML:

content += '<table width="100%" class="confirmRowStyle"><tr>'
                +  '<td class="acCol8 linkeDetail">'+ T24Acclink[i].AccID +'</td>'
                +  '<td class="acCol8">'+'<div class="switch">'
                +  '<input id="cmn-toggle-'+(i+1)+'" class="cmn-toggle cmn-toggle-round" type="checkbox" name="checked"><label for="cmn-toggle-'+(i+1)+'" data-toggle="toggle"></label>'
                +  '</div>'
                +  '</tr></table>';
        linkAcc.setHtml(content);  

1 个答案:

答案 0 :(得分:0)

    try this
in your listeners
listeners:{
                        element: 'element',
                        delegate: 'div.switch',
                        change: function(el,checked,items){
                            console.log(el.currentTarget.getAttribute("data-id"))
                            }
                        }

in your html pass attribute in div 
  +  '<td class="acCol8">'+'<div class="switch" data-id="putyouvaluehere">'
you can set dynamic value too