Results 1 to 6 of 6

Thread: Notify child of parent's events

  1. #1
    Sencha User
    Join Date
    Mar 2007
    Posts
    443
    Answers
    5
    Vote Rating
    18
      0  

    Default Notify child of parent's events

    What's a good pattern for notifying a child component when an event happens in a parent component?

    For example, I have a subclass of Ext.tab.Panel, which is designed to work with Ext.navigation.Views as children (similar to the iPhone App Store).

    I want it to notify one of its child items when the selected tab is re-tapped, so the navigation view can reset to its initial view. But I'd like the child to be responsible for knowing how to reset itself.

    It seems like I should have the child listen for an event from the parent. But how would I tell the child to add this event listener?

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Answers
    3976
    Vote Rating
    1367
      0  

    Default

    Each child of a tabpanel (card layout for that matter) will fire an activate method when that view is set active.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Posts
    443
    Answers
    5
    Vote Rating
    18
      0  

    Default

    But that won't fire when you re-tap the tab that's already active.

  4. #4
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Answers
    3976
    Vote Rating
    1367
      0  

    Default

    What on the parent will fire when you do that? You can listen for when the tab instance is tapped on and get the activeitem of the tabpanel but that won't work when the activeitem changes.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Posts
    443
    Answers
    5
    Vote Rating
    18
      0  

    Default

    Nothing will; that's why I had to create a custom subclass and override some methods, so it would fire an event when a tab was tapped.

    My question isn't really meant to be specific to TabPanels, though. I'm wondering more about the general idea of informing a child component of a parent's events.

    (Although while we're on the topic of TabPanels, it would be helpful if Ext fired an event when the selected tab was re-tapped.)

  6. #6
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,029
    Answers
    3976
    Vote Rating
    1367
      0  

    Default

    You can do it two ways...

    Put a listener on the parent and do your action on the child. Or form the child add an event on it's parent and then take action on it.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

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
  •