1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    23
    Answers
    2
    Vote Rating
    0
    francescosyd is on a distinguished road

      0  

    Default Answered: Sencha Architect XTemplate scope

    Answered: Sencha Architect XTemplate scope


    I'm trying to set a scope variable on the itemTpl in an Ext.dataview.List in architect 3.0 Does anyone know how to do this? I can add a scope property on the itemTpl but it seems to convert 'this' to a string.thanksFrancesco

  2. Hi Jason,thanks for the pointer :-) I like using the itemTpl editor in Sencha Architect as it makes it easy to spot mistakes and add template functions. So I kept my template in the lists itemTpl property and added the following on the lists initialize method://re-create template so it compiles to include scopevar itemTpl = this.getItemTpl();itemTpl.scope = this;this.setItemTpl(Ext.create('Ext.XTemplate',itemTpl.html, itemTpl));Now my template functions have access to the required scope via this.scope and I still get to use Architects XTemplate editor.Thanks againFrancesco

  3. #2
    Sencha - Architect Dev Team jjohnston's Avatar
    Join Date
    Sep 2010
    Posts
    537
    Answers
    26
    Vote Rating
    18
    jjohnston will become famous soon enough jjohnston will become famous soon enough

      0  

    Default


    You wouldn't be able to set scope to 'this' directly, because the itemTpl config is assigned at class definition time, not instantiation time, so there is no 'this' reference (actually there is but it points to window.) To do this you would have to do something like override the initialize method and set your itemTpl config there, where 'this' points to the instance being initialized.
    Jason Johnston
    @lojjic
    Sencha Architect Development Team

  4. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    23
    Answers
    2
    Vote Rating
    0
    francescosyd is on a distinguished road

      0  

    Default


    Hi Jason,thanks for the pointer :-) I like using the itemTpl editor in Sencha Architect as it makes it easy to spot mistakes and add template functions. So I kept my template in the lists itemTpl property and added the following on the lists initialize method://re-create template so it compiles to include scopevar itemTpl = this.getItemTpl();itemTpl.scope = this;this.setItemTpl(Ext.create('Ext.XTemplate',itemTpl.html, itemTpl));Now my template functions have access to the required scope via this.scope and I still get to use Architects XTemplate editor.Thanks againFrancesco

  5. #4
    Sencha User
    Join Date
    Dec 2010
    Posts
    23
    Answers
    2
    Vote Rating
    0
    francescosyd is on a distinguished road

      0  

    Default


    Hi Jason,thanks for the pointer :-) I like using the itemTpl editor in Sencha Architect as it makes it easy to spot mistakes and add template functions. So I kept my template in the lists itemTpl property and added the following on the lists initialize method://re-create template so it compiles to include scopevar itemTpl = this.getItemTpl();itemTpl.scope = this;this.setItemTpl(Ext.create('Ext.XTemplate',itemTpl.html, itemTpl));Now my template functions have access to the required scope via this.scope and I still get to use Architects XTemplate editor.Thanks againFrancesco

Thread Participants: 1