YUI ContextMenu 控制MenuItem的显示情况(如disabled)

大家好,老师来了,老师又来了……幸好不收稿费也不收学费。所以一个ContextMenu就可以写n篇,大家也没有什么意见,这次老师要说的是……控制MenuItem的属性。应用场景如下:

针对目标,右键菜单可能启用一些菜单项,禁用一些菜单项。
简单的例子是,选中图片文件可以用Acdsee打开,选中word文件就是用word打开了。

这里的解决思路是从YUI 邮件组搜到的。所以邮件组是个好东西。但是还需要挖掘啊。上面Todd是这么说的。(前文没看,可能Todd刚和文中麦扣打笔战)

 

On Jan  30 ,   2007 ,  at  11 : 54  AM ,  Todd Kloots wrote:


Michael -

If you set the 
" lazyload "  configuration property to
" true "  for your ContextMenu ,  then its contents will
not get created and the menu itself will not be
rendered until the 
" contextmenu "  event is actually
fired.

That said
,  if you're creating a ~ 1000  elements with
unique context menus
,  then ,  yes it would be better to
reuse a single ContextMenu instance and reuse it. You
can subscribe to your context menu's 
" showEvent "  and
use the 
" contextEventTarget "  to determine what child
node was the actual target of the 
" contextmenu "  event
that triggered the display of the menu. You can then
use that target element to determine what content you
need to add or remove from the menu.

Make sense?

- Todd

上下文不重要,重点是这里说明了一个事情,menu是有showEvent这个事件的,往前追溯就是他老爸(的老爸) YAHOO.widget.Module有那么一个东西。继承给Menu-ContextMenu了。所以基于这个showEvent事件触发时,兄弟们去取menu.contextEventTarget。就能拿到目标的那个DOM对象了。
拿到这个对象后,就可以根据对象的数据(属性)来决定要不要显示一些菜单。代码如下。照旧片断.

先注册

        oContextMenu.showEvent.subscribe(onContextMenuShow, this );


然后读取数据就行了。外面的鞭炮声和爆炸案有得一拼

         function  onContextMenuShow()  {


                disabledMenu(oContextMenu.contextEventTarget);
                
        }




        
function  disabledMenu(vo) {
            
//alert(oTarget.first);
                if(vo.last||vo.dataType=='m'){
                    oContextMenu.getItem(
4).cfg.setProperty("disabled"true);
                    
//alert(oContextMenu.getItem(3));
                }
else{
                    oContextMenu.getItem(
4).cfg.setProperty("disabled"false);
                }

                
                
if(vo.first||vo.dataType=='m'){
                    oContextMenu.getItem(
3).cfg.setProperty("disabled"true);
                }
else{
                    oContextMenu.getItem(
3).cfg.setProperty("disabled"false);

                }


        }


 问题就是这样解决的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值