本文介绍了xpages - 如何从客户端 javascript 设置范围变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从客户端 JavaScript 设置 XPages 范围变量.我有一个 XPage,其中包含使用 Dojo 显示或隐藏的几个部分.在这个 XPage 上,我有一个按钮可以执行一些服务器端 JavaScript.一旦按钮后面的 SSJS 执行,默认情况下可见的 XPage 部分将再次可见,而不是在单击按钮之前立即可见的部分.我希望在单击按钮之前可见的部分在按钮后面的 SSJS 执行后也可见.

I'm trying to set an XPages scope variable from Client side JavaScript. I have an XPage which contains several sections which are shown or hidden using Dojo. On this XPage I have a button which executes some server side JavaScript. Once the SSJS behind the button executes, the section of the XPage which is visible by default is again visible, rather than the section which was visible immediately prior to the button being clicked. I would like the section which was visible prior to the button being clicked to also be visible after the SSJS behind the button has executed.

为此,我想到了使用范围变量 - 使用客户端 JavaScript 计算 XPage 的当前可见部分,在范围变量中设置该值并在 onClientLoad 事件再次使该部分可见(并隐藏所有其他部分).但是,我发现无法从客户端 JavaScript 设置范围变量.我试过添加

To do this I have thought of using a scope variable - use client side JavaScript to calculate which section of the XPage which is currently visible, set this value in a scope variable and read the scope variable in the onClientLoad event of the XPage to again make this section visible (and hide all other sections).However, I have found no way of setting a scope variable from client side JavaScript. I have tried adding

var xyz = "#{javascript:viewScope.put('sectionDisplay','Section')}"

到按钮的 onClick 客户端事件,但这会设置范围变量,无论按钮是否被点击.

to the onClick client event of the button but this sets the scope variable regardless of whether the button is clicked or not.

在 XPage 之前,我会使用查询字符串将变量从一个页面传递到另一个页面.我现在该怎么做?

Before XPages, I would have used the querystring to pass variable from one page to another. How can I now do this?

推荐答案

另一种方法:也许你根本不需要作用域变量,如果你只是想隐藏一些东西,你可以将它的样式属性设置为显示:没有任何".

One other approach: perhaps you don't need the scope variable at all, if you just want to hide something, you can set it's style property to "display:none".

例如,您有这个 div:<xp:div id="mydiv">...</xp:div>

For example, you have this div: <xp:div id="mydiv">...</xp:div>

然后你可以在按钮中使用以下 CSJS:

Then you can use the following CSJS in a button:

dojo.byId("#{id:mydiv}").style.display="none"

这篇关于xpages - 如何从客户端 javascript 设置范围变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 23:38