
Originally Posted by
jinyoungc
Hi Halesway, Could you offer up a code snippet for dynamically updating the list from a store? I was able to achieve something like that by creating a function to loop through my store and add the object to the items array. However, I don't know where to add that function so that the items object would be rendered in the view.
Any kind of help would be greatly appreciated. Thanks!
Hi,
Sorry for the delayed response, only just seen this thread again today.
Yeah, it took a bit of trial and error and educated guessing honestly to get it working how I wanted. wneilson himself may well cringe at my solution but I wasn't 100% certain what every bit of his code did so some bits might not be applicable to the actual solution. Anyways this is how I got it working for my particular app...
For reasons I wont go in to, we were actually populating the slide menu items with just a hard coded array of new items rather than pulling new items from a store but hopefully it should still be translatable.
I've slightly renamed some attributes and simplified but this is basically the app code:
The contents of my slideMenu instance:
Code:
config: {
id: 'exampleSlideOutMenu',
title: 'Home',
iconCls: 'home',
selectSlideDuration: 200,
list: {
maxDrag: 300,
width: 260,
name: 'exampleList',
items: [{
xtype: 'toolbar',
docked: 'top',
ui: 'slideMenuUI',
title: {
title: 'Example',
width: 200,
style: 'text-align: left',
left: 0
},
layout: {
pack: 'right'
},
items: [
{
xtype: 'button',
iconCls: 'delete',
iconMask: true,
action: 'closeMenu',
ui: 'slide-menu-btn'
}
]
}]
},
defaults: {
xtype: 'container'
},
items: defaultMenuItems
}
Then in my controller (simplified for here), this is what gets called within a function when I click on a button on my home page that needs to load in the new items in to the slide menu list:
Code:
menu = Ext.getCmp('exampleSlideOutMenu');
menu._indexCount = 0;
menu.store.removeAll();
delete menu.config.items;
menu._cache = {};
menu.addItems(dynamicMenuItems);
menu.openContainer();
My app made things slightly more awkward in that it was split in to two main areas. Within each area there are 4 buttons, each which load a new set of items for the menu. I had to make two instances of the slideMenu - one for each side - which to begin with seemed to cause problems because you went to one side and the correct items were shown in the list, but if you actually clicked on one, it was still loading in the pages from the other side.
I found that by including the bits in red, I was able to clear/reset the menu's main variables and load in the fresh new items properly. I don't know if these will apply to you if you only have one instance of the slideMenu, but that's what worked for me.
Hope this helps,
Halesway