PDA

View Full Version : Multiple update event fired for one update action



stonecracker
7 Nov 2006, 7:38 PM
I found a mysterious behavior about onUpdate of UpdateManager: Fire multiple update event during on actual update action

The following is the code snippnet catch the bug, when bring out the context menu multiple times, there are N(number of previous update action) update event fired for any-single-context-menu-popout. The update event was remembered!

Is this is a bug or my mistake?




// initialize all
cm_init = function(e){
console.info("catched context menu onUpdate: %s, %.o",e, e)
// get links in the context menu
var cm_ajax_page = YAHOO.util.Dom.getElementsByClassName("ajax-panel", "a", "inquiryitem-context-menu");
// add callback for the links in the context menu
YAHOO.util.Event.addListener(cm_ajax_page, 'click', get_ajax_in_panel);
};

//fire a XHR call to get the context menu content as menu element
function call_context_menu(rowIndex, e){
var mgr = cm_div.getUpdateManager();
mgr.loadScripts = true;
id=grid.getSelectedRowId();
mgr.update('/inquiry/ajax/get_inquiryitem_action/'+id+'/');
//when context menu finshed loading, tigger initilization of the context menu links
mgr.onUpdate.subscribe(cm_init);
console.info("added onUpdate for context menu, %s, %.o", e, e);
};

// Add a listener of rightclick in the grid and calls out context menu
grid.addListener('rowcontextmenu', call_context_menu);

jack.slocum
7 Nov 2006, 8:26 PM
This is the desired behavior. The update event is not a callback, it's an event. When you register a listener multiple times, it will get called multiple times. Think of it like a click handler, if you register multiple handlers, they will all be called each time it is clicked. The update event works the same.

If what you want is a callback, there a callback parameter on the update method.

stonecracker
7 Nov 2006, 11:27 PM
Thanks jack, you are right. I want a handler so it should be initialized only once for my case.

Thanks for your great help!