开发者

How to pass event and other arguments in grid's context menu item handler?

I'm using Dojo 1.5, and I'm trying to create a context menu that can invocate a function myFunction passing the event and other arguments. So far I've the following code:

    <div dojoType="dijit.Menu" id="bankerMenu" style="display: none;">
        <div dojoType="dijit.MenuItem" onclick="copyDocuments('bankerFolder');" iconClass="dijitEditorIcon dijitEditorIconCopy">Copy to Client</div>
            <div dojoType="dijit.PopupMenuItem" onclick="doNothing()" iconClass="dijitEditorIcon d开发者_运维百科ijitEditorIconCopy">
                <span><s:text name="CopyTo.label"/></span>
                <div dojoType="dijit.Menu" id="bigsubmenu">
var="distributionList">
                        <div dojoType="dijit.MenuItem" onclick="myFunction(event,'bankerFolder',1)"><s:property value='distributionListName'/></div>
                </div>
            </div>
    </div>

But it is not recognizing the 'event' that I want to pass to the function. I know I can susbtitute the call using this:

            <div dojoType="dijit.MenuItem" label="Some menu item 2">
                <script type="dojo/method" event="onClick" args="evt">
                    myFunction(evt,'bankerFolder',1);
                </script>
            </div> 

but I would like to simplify it and used the first syntax. How can I do that?


Passing event literally would likely end up leaving you at the mercy of cross-browser inconsistencies. However, since events connected through Dojo worry about this for you, and since onClick is a widget event that already receives the event object as an argument, you should be able to get away with the following:

<div dojoType="dijit.MenuItem" onClick="myFunction(arguments[0],'bankerFolder',1)"><s:property value='distributionListName'/></div>

Also note the capital C in onClick - widget events always use camel case; they are not actual DOM events, though they are often mapped to analogous DOM events. I get the impression you were testing with capital C though, based on the problem you described encountering.

Here's a simplified example of the idea working (initially provided/suggested by Dustin Machi in the Dojo IRC channel): http://jsfiddle.net/xwFC5/5/


Following from Ken's comment to the answer above, I managed to figure this out as outlined here: http://blue-networks.net/wp/?p=37 It connects to onCellContextMenu and pulls the relevant information out of the event, saving it into the grid object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜