问题
I have a toolbar with two basicLeafNodes in which I need to call some CSJS when they are clicked. To do this I put the CSJS in the onClick event of the basicLeafNode but when I do this, regardless of whether I return true, false or no return at all, the eventHandler for event="onItemClick" does not execute. If I remove the CSJS in the onClick event then onItemClick executes. Any ideas on what I am doing wrong here?
<xe:toolbar>
<xe:this.treeNodes>
<xe:basicLeafNode label="Back" submitValue="Back"></xe:basicLeafNode>
<xe:basicLeafNode label="Save & Back" submitValue="SaveAndBack" loaded="${javascript:document1.isEditable()}" onClick="console.log('save and back clicked');"></xe:basicLeafNode>
<xe:basicLeafNode label="Edit" submitValue="Edit" loaded="${javascript:!(document1.isEditable())}"></xe:basicLeafNode>
<xe:basicLeafNode label="Save" submitValue="Save" loaded="${javascript:document1.isEditable()}" onClick="console.log('save clicked'); return true;"></xe:basicLeafNode>
<xe:basicLeafNode label="Delete"></xe:basicLeafNode>
</xe:this.treeNodes>
<xp:eventHandler event="onItemClick" submit="true" refreshMode="partial" refreshId="dc" disableValidators="#{javascript:context.getSubmittedValue() == 'Back'}">
<xe:this.action>
<![CDATA[#{javascript:
vendor.runAction(context.getSubmittedValue(), document1);
}]]></xe:this.action>
</xp:eventHandler>
</xe:toolbar>
回答1:
basicLeafNode
's onClick event overwrites toolbar
's onItemClick event.
This is visible in rendered page source.
Just turn it around: add your client side actions into toolbar
's onItemClick event.
You can get the clicked label with
var node = thisEvent.target.parentNode;
var label = node.getElementsByClassName('dijitButtonText')[0].innerHTML;
and add your code depending on clicked label.
Here is a working XPage example:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:toolbar>
<xe:this.treeNodes>
<xe:basicLeafNode
label="first"
submitValue="first">
</xe:basicLeafNode>
<xe:basicLeafNode
label="second"
submitValue="second">
</xe:basicLeafNode>
</xe:this.treeNodes>
<xp:eventHandler
event="onItemClick"
submit="true"
refreshMode="complete">
<xe:this.script><![CDATA[
var node = thisEvent.target.parentNode;
var label = node.getElementsByClassName('dijitButtonText')[0].innerHTML;
alert('action for: ' + label);
return true;
]]></xe:this.script>
<xe:this.action><![CDATA[#{javascript:
print(context.getSubmittedValue());
}]]></xe:this.action>
</xp:eventHandler>
</xe:toolbar>
</xp:view>
来源:https://stackoverflow.com/questions/37867543/cannot-get-xpages-toolbar-onitemclick-event-to-execute-when-basicleafnode-contai