скрыть и показать элемент - PullRequest
3 голосов
/ 15 марта 2012

В этот раз моя проблема - заставить предмет появляться и исчезать.Я знаю, что это делается с hide() и show(), но я не знаю, как?Вот мой кодЯ хочу, чтобы xtype появился: «datepickerfield», когда я выбираю «Appointment» в «selectfield»

App.views.Bankingrendezvous = Ext.extend(Ext.Panel, {

items: [{
xtype: 'formpanel',
id: 'form',
fullscreen: true,
scroll: 'vertical',
items: [{

       xtype: 'fieldset',
       title: 'Information & Appointment',
    },
    {
        xtype: 'selectfield',
        id: 'request',
        label: 'You need',
        options: [ 
        {   
            text: 'Appointment',
            value: 'Appointment'
        },
        {   
            text: 'Information',
            value: 'Information',

        }]



    },
    {
xtype: "datepickerfield",
id: "startDate",
label: "when",
picker: { yearFrom: 2012, yearTo: 2020} 

    },}]
     }]
     });
    Ext.reg('Bankingrendezvous', App.views.Bankingrendezvous);

спасибо.Я пытался, как вы говорите:

  {
xtype: "datepickerfield",
id: "startDate",
label: "when",
picker: { yearFrom: 2012, yearTo: 2020}
    this.items.getAt().hide();
 },

, но это не работает.


items: [{
xtype: 'formpanel',
 id: 'form',
fullscreen: true,
scroll: 'vertical',
items: [{

       xtype: 'fieldset',
       title: 'Information & Appointment',
    },
    {
        xtype: 'selectfield',
        id: 'request',
        label: 'You need',
        options: [ 
        {   
            text: 'Appointment',
            value: 'Appointment'
        },
        {   
            text: 'Information',
            value: 'Information',
        }],
     listeners: {
         function()
                  {
                    if (Ext.getCmp('request').getValue() == 'Information')
                      {
                        Ext.getCmp('startDate').hide();
                      }
                  }
               },


    },
     {
 xtype: "datepickerfield",
 id: 'startDate',
 label: "when",
 picker: { yearFrom: 2012, yearTo: 2020},        
      },

Я пробовал это, но это не работает

1 Ответ

5 голосов
/ 15 марта 2012

Вы можете использовать любой из двух методов: hide()/show() или setVisible(true/false).

Если вы хотите получить доступ к своим элементам внутри объекта (например, внутри события initComponent ()), используйте следующее предложение:

this.items.getAt(<index of item>).hide();
this.items.getAt(<index of item>).show();

Чтобы установить доступ к элементу вне класса, вы делаете это с помощью метода getCmp ():

var el = Ext.getCmp("elementID");

, а затем получаете доступ к элементу и устанавливаете его видимость.

el.items.getAt(<index of item>).setVisible(false); // hide
el.items.getAt(<index of item>).setVisible(true); // show 
...