PDA

View Full Version : Ext.menu.Menu scope and handler



stever
31 May 2007, 3:03 PM
It would be great if a menu could have a base scope and handler such that I could do this:


{
text: 'SubMenu',
menu:
{
items: [
{
text: 'One',
privateArg: 1
},
{
text: 'Two',
privateArg: 13
},
{
text: 'Hello',
privateArg: 12
},
{
text: 'Not',
privateArg: 11
},
{
text: 'Other',
privateArg: 2
}
],
scope:someObj,
handler:someObj.fn
}
}

instead of this:


{
text: 'SubMenu',
menu:
{
items: [
{
text: 'One',
privateArg: 1,
scope:someObj,
handler:someObj.fn
},
{
text: 'Two',
privateArg: 13,
scope:someObj,
handler:someObj.fn
},
{
text: 'Hello',
privateArg: 12,
scope:someObj,
handler:someObj.fn
},
{
text: 'Not',
privateArg: 11,
scope:someObj,
handler:someObj.fn
},
{
text: 'Other',
privateArg: 2,
scope:someObj,
handler:someObj.fn
}
]
}
}

zquirm
31 May 2007, 3:48 PM
I agree...this would be very useful. You could then use the item handler to override the main handler if one item needed to be different.

jack.slocum
31 May 2007, 8:46 PM
Each menu is independent of others. Why not instead use the flexibility of JS and just create an internal function? It ends up even shorter in the end.


function item(text, arg){
return {
text: text,
privateArg: arg,
scope:someObj, // via closure
handler: someObj.fn
};
}

Then:


....
items: [
item('One', 1),
item('Hello', 13),
item('Not', 12),
item('Other', 11)
]

KimH
1 Jun 2007, 2:41 AM
Jack I really like the way you think and do JavaScript!

It's so simple.... yet so powerfull B)

jack.slocum
1 Jun 2007, 4:04 AM
Jack I really like the way you think and do JavaScript!

It's so simple.... yet so powerfull B)

I'm terrible at typing so shortcuts are a must! ;)

stever
1 Jun 2007, 8:38 AM
Each menu is independent of others. Why not instead use the flexibility of JS and just create an internal function? It ends up even shorter in the end.


I had ended up with something like items.each(function(item){}(item.scope=obj;...

But now I see there are much better ways!

KimH
4 Jun 2007, 12:52 PM
I'm terrible at typing so shortcuts are a must! ;)
:)) Ha, ha...touch