Extjs 4 How to get id of parent Component?

后端 未结 2 696
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 01:23

I have multiple fieldset. And have Button inside each fieldset in Extjs 4. I want to get fieldset id on the button click event, so that i can know from which fieldse

相关标签:
2条回答
  • 2021-01-05 01:30

    I've implemented handler properly.

    {
        xtype:'fieldset',
        id:'fs1',
        items:[{
            xtype:'button',
            id:'b1',
            handler:function(btn){
                // Retrieve fieldset. 
                var fieldset = btn.up('fieldset');
                // Retrieve Id of fieldset.
                var fieldsetId = fieldset.getId();
            }
        }]
    }
    

    In that case try this:

    button.up("[xtype='fieldset']")
    

    0 讨论(0)
  • 2021-01-05 01:43
    Ext.onReady(function() {
      var panel = Ext.create('Ext.panel.Panel', {
          items:  {
            xtype:'fieldset',
            id:'fs1',
            items:[{
              xtype:'button',
              id:'b1',
              handler:function(b,e){
                var fieldset = b.findParentByType('fieldset');
                var fieldsetID = fieldset.getId();
                console.log(fieldsetID);
              }
            }]
          },
          renderTo: document.body
      });
    });
    

    Notice, that once you have fieldset variable, you can actually add items to this container directly, without need to use its ID

    0 讨论(0)
提交回复
热议问题