2

In the code (I use MVC model if it matters), to get a specific elements, I use refs.

refs: [
    {
        ref: 'window',
        selector: 'windowName'
    },
    {
        ref: 'windowButton',
        selector: 'windowName button[name=buttonName]'
    },
    {
        ref: 'windowCombo',
        selector: 'windowName combo[name=comboName]'
    }
]

Is this the right choice to get an elements? Or I have to use getCmp() or something else?

Sergey Novikov
  • 4,096
  • 7
  • 33
  • 59
  • That works, of course, and is far better than using getCmp(). Do you need the refs for the buttons, though? You can always use the hierarchy traversal methods (up(), down(), etc) to get children of the window: this.getWindow().down( '[name=buttonName]' ), or this.getWindow().down( '#buttonItemId' ) – existdissolve Oct 14 '13 at 16:04
  • Thanks for answer. I need references to buttons, various filds, panels etc. Is there best method to get them all or it depends of situation? As for the up() and down(), how should I use them if I want to select a combo inside, for example, window-form-panel-panel? Should I use this.getMyWindow.down().down().down().down(name=myCombo)? And is it better then refs? – Sergey Novikov Oct 14 '13 at 18:24

1 Answers1

4

Here are some tips on targeting a component in an app.

  1. First of all be very careful using IDs on the components. I have seen my fair share of problems with them. Avoid at all cost.

  2. Second, ExtJS provides several ways of targeting Components and Elements. Don't mix the two.

    For Components:
        • Ext.getCmp(id)
        • Ext.ComponentQuery.query() 
        • up() 
        • down() 
        • nextSibling() 
        • previousSibling()
        • child()
        • previousNode()
    plus various find.. Methods
    
    For Elements:
        • Ext.get()
        • Ext.dom.Query() 
    

    (more on DOM Query http://docs.sencha.com/core/manual/content/domquery.html

Community
  • 1
  • 1
dbrin
  • 15,525
  • 4
  • 56
  • 83
  • Instead of the `id` property use `ìtemId`. An `id` must be unique on the document. An `itemId` must be unique inside a component. – Lorenz Meyer Oct 14 '13 at 17:57
  • Thanks for answer. If I want to select a combo inside, for example, window-form-panel-panel what should I use? And is it better then refs? – Sergey Novikov Oct 14 '13 at 18:27
  • Refs are convenient reusable shortcuts to otherwise potentially long ComponentQuery selectors. Use them when it makes sense. They are just shortcuts and so are the same as using ComponentQuery expressions. – dbrin Oct 14 '13 at 20:36