2017-09-08 1 views
1
var radioGroup = { 
     xtype: 'radiogroup', 
     vertical: 'true', 
     columns: 1, 
     width: 200, 
     items: [{ 
        boxLabel: 'Select Predefined interval', 
        name: 'timeInterval', 
        id: 'selectPredefinedInterval', 
        inputValue: 'predefined', 
        listeners: { 
         change: function(rf, newValue, oldValue) { 
          if (newValue) { 
           Ext.getCmp('predefinedDatePanel').show(); 
          } else { 
           Ext.getCmp('predefinedDatePanel').hide(); 
          } 
         } 
        } 

       }, 
       { 
        boxLabel: 'Specify last X hours/days', 
        name: 'timeInterval', 
        id: 'SpecifyLastHours', 
        inputValue: 'lasthours', 
        listeners: { 
         change: function(rf, newValue, oldValue) { 
          if (newValue) { 
           Ext.getCmp('lastXDatePanel').show(); 
          } else { 
           Ext.getCmp('lastXDatePanel').hide(); 
          } 
         } 
        } 


       }, 
       { 
        boxLabel: 'Specify date or interval', 
        name: 'timeInterval', 
        id: 'specifiedDate', 
        inputValue: 'specifydate', 
        listeners: { 
         change: function(rf, newValue, oldValue) { 
          if (newValue) { 
           Ext.getCmp('specifyDatePanel').show(); 
          } else { 

           Ext.getCmp('specifyDatePanel').hide(); 
          } 
         } 
        } 



       }, 
+1

하십시오 Sencha fiddle example는 제대로 – Derlin

+0

현재 내가 데 리스너를 포맷합니다. 코드를 읽을 수 없습니다. – user6454237

+0

@ user6454237 코드를 먼저 포맷 마십시오 하나의 수신기를 사용하는 방법을 그 대신에 모든 라디오 필드에 대한 코드 – UDID

답변

3

+0

값이 참이라면 언급 된 패널을 호출하지 않습니다. – user6454237

+0

예 : if (true) {Ext.getCmp ('predefinedDatePanel'). show(); }이 패널을 호출해야하지만 해당 패널을 호출하는 대신 else if if 문으로 이동합니다. – user6454237

+0

@ user6454237 이제 check code가 업데이트되었습니다. "getValue"의 잘못된 주문을 작성했습니다. –

0

:) .. "& & NEWVALUE가"... 덕분에 필요하지 않습니다 .. 당신을 위해 일 할 수있는, 같이 할 사실

var radioGroup = { 
     xtype: 'radiogroup', 
     vertical: 'true', 
     columns: 1, 
     width: 200, 
     items: [{ 
       boxLabel: 'Select Predefined interval', 
       name: 'timeInterval', 
       id: 'selectPredefinedInterval', 
       inputValue: 'predefined' 
      }, 
      { 
       boxLabel: 'Specify last X hours/days', 
       name: 'timeInterval', 
       id: 'SpecifyLastHours', 
       inputValue: 'lasthours', 
      }, 
      { 
       boxLabel: 'Specify date or interval', 
       name: 'timeInterval', 
       id: 'specifiedDate', 
       inputValue: 'specifydate' 
      } 
     ], 
     listeners: { 
      change: function(radio, newValue, oldValue) { 

       Ext.getCmp('predefinedDatePanel').hide(); 
       Ext.getCmp('lastXDatePanel').hide(); 
       Ext.getCmp('specifyDatePanel').hide(); 

       if (radio.getValue().timeInterval == 'predefined' && newValue) { 
        Ext.getCmp('predefinedDatePanel').show(); 
       } else if (radio.getValue().timeInterval == 'lasthours' && newValue) { 
        Ext.getCmp('lastXDatePanel').show(); 
       } else if (radio.getValue().timeInterval == 'specifydate' && newValue) { 
        Ext.getCmp('specifyDatePanel').show(); 
       } 
      } 
     } 

    }, 

시도하십시오 ExtJs에서 라디오 그룹 이벤트가 있습니다. 당신이 참조 할 수 있습니다 ExtJs docs

귀하의 요구 사항에 따라, 어떻게 작동하는지 보여주기 위해 작은 데모를 만들었습니다.

Ext.create('Ext.form.Panel', { 
    title: 'RadioGroup Example', 
    width: '100%', 
    height: 500, 
    itemId: 'myPanel', 
    bodyPadding: 10, 
    renderTo: Ext.getBody(), 
    dockedItems: [{ 
     xtype: 'toolbar', 
     defaults: { 
      hidden: true 
     }, 
     items: [{ 
      html: 'predefinedDatePanel', 
      itemId: 'predefined' 
     }, { 
      html: 'lastXDatePanel', 
      itemId: 'lasthours' 
     }, { 
      html: 'specifyDatePanel', 
      itemId: 'specifydate' 
     }] 
    }], 
    items: [, { 
     xtype: 'radiogroup', 
     vertical: 'true', 
     columns: 1, 
     width: 200, 
     listeners: { 
      change: function (rf, newValue, oldValue) { 
       var myPanel = rf.up('#myPanel'); 
       myPanel.down('toolbar').items.items.map(item => { 
        item.hide(); 
       }) 
       myPanel.down(`#${newValue.timeInterval}`).show(); 
      } 
     }, 
     items: [{ 
      boxLabel: 'Select Predefined interval', 
      name: 'timeInterval', 
      id: 'selectPredefinedInterval', 
      inputValue: 'predefined' 

     }, { 
      boxLabel: 'Specify last X hours/days', 
      name: 'timeInterval', 
      id: 'SpecifyLastHours', 
      inputValue: 'lasthours' 

     }, { 
      boxLabel: 'Specify date or interval', 
      name: 'timeInterval', 
      id: 'specifiedDate', 
      inputValue: 'specifydate' 
     }] 
    }] 
});