Results 1 to 2 of 2

Thread: Why the refs to itemId cannot trigger the initialize event in Sencha Touch?

  1. #1
    Sencha User
    Join Date
    May 2014
    Posts
    1

    Default Answered: Why the refs to itemId cannot trigger the initialize event in Sencha Touch?

    This is the controller code:


    Code:
        Ext.define('XXX.controller.XXX', {
            extend: 'Ext.app.Controller',
            config: {
                views: ['CustomView','CarouselView'],
                refs: {
                    custom: "carouselview #customid"
                },
                control: {
                    custom: {
                        initialize : function() {
                            alert("it's loading")
                        }
                    }
                }
            },
            launch: function(){
                Ext.Viewport.add(Ext.create('XXX.view.CustomView'));
                console.log(this.getCustom())      // > This works, it is not undefined
            }
        });
    and this is the carousel view code:


    Code:
        Ext.define('XXX.view.CarouselView', {
            extend: 'Ext.Carousel',
            xtype: 'carouselview',
        
            defaults: {
                styleHtmlContent: true
            },
        
            config:{
                direction: 'horizontal',
                items: [
                    {
                        xtype: 'customview',
                        itemId: 'customid'
                    }
                ]
            }
        });
    Now it's the customview :


    Code:
        Ext.define('XXX.view.CustomView', {
            extend: 'Ext.Panel',
            xtype: 'customview',
            config: {
                tpl:  XXX
            }
        });
    in the controllers's launch function, it can log the right value, but the initialize event can't be triggered.
    And if i change refs to { custom: "customview" }, the initialize event can be triggered.

    #customid view is a subitem of carouselview. This selector works fine becausethis.getCustom() is a valid value means the correct component has been referenced. but i don't know why it doesn't work with the initialize function

  2. Refs can't have itemIds in them. I'm not sure of the reasoning for this but that's the way it is. If you really want to target using itemIds you could use the property syntax like [itemId="myItemId"]

  3. #2
    Sencha Premium User StuartAshworth's Avatar
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    418
    Answers
    17

    Default

    Refs can't have itemIds in them. I'm not sure of the reasoning for this but that's the way it is. If you really want to target using itemIds you could use the property syntax like [itemId="myItemId"]
    SenchaTalk.com - a free Slack community for all things Sencha. Join Now!

    Learn Ext JS 6 with my new ebook - Ext JS 6: Getting Started. Get a Sample Chapter now!

    Need help with Sencha development, code reviews or training? Get in touch!

    [email protected]
    @StuartAshworth9

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •