问题描述
我正在服务器端 javascript (SSJS) 按钮中设置 viewScope 变量.
I am setting a viewScope variable in a server side javascript (SSJS) button.
viewScope.put("branchName",doc.getItemValueString("BranchName"))
viewScope.put("branchName",doc.getItemValueString("BranchName"))
如何在客户端访问该变量?
How can I access that variable on the client side?
推荐答案
如果您需要从客户端脚本访问 viewScope 变量,您可以使用 xp:scriptBlock 标记来设置多个全局 javascript 变量.
If you need to access the viewScope variable from a client side script you can use the xp:scriptBlock tag to setup a number of global javascript variables.
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[var myVar = #{javascript:viewScope.get("scopeVar")}]]></xp:this.value>
</xp:scriptBlock>
这种方法的主要问题是内部服务器端 javascript 仅在该元素最初呈现或对元素执行部分刷新时才计算,因此不能保证客户端 JS 变量设置为正确的值.
The main problem with this method is that the inner server side javascript is only computed when that element is initially rendered or when a partial refresh is performed on the element so there is no guarantee that the client side JS variable is set to the correct value.
这篇关于在 XPage 上的客户端 javascript (CSJS) 中获取范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!