-
3 Mar 2007 4:31 AM #1
Ext.menu.Menu.items: How to add a handler to existing items?
Ext.menu.Menu.items: How to add a handler to existing items?
I managed to feed a Menu with JSON data. Now I want to add a handler to each Menu Item. I tried many things but I never had any success:
Acutally I want to achieve that the same function is called by each item with the according item id as argument.Code:... var menuC = new Ext.menu.Menu({ id: 'mainMenu', items: Ext.decode(responseText) }); menuC.items.get(1).handler = 'function(arg){alert();}'; menuC.items.get(1).on("click", menuC.items.get(1).target, menuC.items.get(1).scope, true); ...
Please Help
-
3 Mar 2007 5:43 AM #2
After hours of trying the solution was that simple:
Code:menuC.on('click', function(menu, item){ alert('Item "' + item.id + '" at Menu: ' + menu.id + ' was clicked.'); });
-
15 Mar 2007 10:14 PM #3
oxi,
I am looking to do a json linked menu just like you are doing and could use some guidence on how the response text looked like from the jsondata. Or how you made the request to the data. Any code on that would be a great help and save me a few hours of banging my head.
At first I was tring to do a no toolbar menu like:

http://www.herbarium.lsu.edu/advancedimagesearch.php (Old YUI Concept)
This was done with YUI a long time back but now tring to replicate this feature somehow in a Ext version. I might end up in a toolbar if anyone has an idea of how to pull this off any direction would be great.
-
15 Mar 2007 10:36 PM #4
A menu bar example here: http://www.yui-ext.com/forum/viewtop...start=15#15763
Jack is going to adopt it in a future version of Ext, so look for an improved version to be available soon. The interface souldn't change too much though, you should be able to accommodate any changes easily.
-
15 Mar 2007 10:49 PM #5
Thanks animal for the update. I looked at that post but it is too late to wrap my mind around anything.
I did give oxi idea some thought and this is what I came up with. There may be a better way to generate a menu from server data onthe fly but this works for me for now.
I hope this might help someone or if anyone sees a betterway to improve my thinking using a json store or something great. now I need some sleeeeeppp.....Code://---------------------------------------------------------- // Create Menu for Image Filter // Sample Response Text = "[{text: 'Item 1'},{text: 'Item2',menu: { items: [{text: 'Sub 1'}] }}]" //---------------------------------------------------------- Ext.get('images-cp').createChild({tag:'div',id:'images-menubar'}); var menuSuccess = function(o){ if(o.responseText){ var menu = new Ext.menu.Menu({ id: 'mainMenu', items: Ext.decode(o.responseText) }); var tb = new Ext.Toolbar('images-menubar'); tb.add({ cls: 'x-btn-text', // icon and text class text:'Image Filter', menu: menu }); } } YAHOO.util.Connect.asyncRequest('GET', 'util/get-filter-menu.php', {success: menuSuccess}); //----------------------------------------------------------
Similar Threads
-
Dragging Tree Items over iFrames
By cogitatio in forum Ext 1.x: Help & DiscussionReplies: 3Last Post: 30 Dec 2008, 12:04 PM -
How to add right click menu to selected items in grid?
By KRavEN in forum Ext 1.x: Help & DiscussionReplies: 5Last Post: 13 Sep 2007, 2:30 AM -
IE6 Nonsecure items message for SSL
By vtswingkid in forum Ext 2.x: Help & DiscussionReplies: 11Last Post: 10 Jul 2007, 2:05 AM -
Right-aligned items in the toolbar
By soad in forum Ext 1.x: Help & DiscussionReplies: 5Last Post: 2 Apr 2007, 5:25 AM -
Focus left on menu items
By KimH in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 22 Feb 2007, 4:20 PM


Reply With Quote