XForms:在节点集绑定中使用计算和 xxforms:default 属性
我有 form1 将查询字符串参数(param1)传递给 form2。我从 form1 传递 param1=true 。在表单 2 中,我尝试将 param1 的值设置到本地实例中。如果我不从表单 1 传递 param1,我希望 form2 将 param1 的值设为 false。这是我的例子。
<xforms:instance id="querystring-instance">
<query-string>
<param1></param1>
</query-string>
</xforms:instance>
我使用以下行通过从查询字符串中获取 param1 的值来设置它。如果查询字符串没有 param1,我想使用默认值 false。
<xforms:bind nodeset="instance('querystring-instance')/param1" calculate="xxforms:get-request-parameter('param1')" xxforms:default="false()" />
这是行不通的。如果 param1 存在,它将起作用并将查询字符串实例设置为 true。如果 param1 不存在,则设置为空。我希望将其设置为 false。我该怎么做?
I have form1 passing a query string parameter(param1) to form2. I pass param1=true from form1. In form 2, I am trying to set the value of the param1 into a local instance. If I DO NOT pass param1 from form 1, I want form2 to take the value of param1 to be false. Here is my instance.
<xforms:instance id="querystring-instance">
<query-string>
<param1></param1>
</query-string>
</xforms:instance>
I am using the following line to set the value of param1 by fetching it from the query string. If query string does not have param1, I want to use the default value of false.
<xforms:bind nodeset="instance('querystring-instance')/param1" calculate="xxforms:get-request-parameter('param1')" xxforms:default="false()" />
This does not work. If param1 is present it works and sets the in querystring-instance to true. If param1 is not present, it sets to nothing. I want it to be set to false. How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能只想在初始化时设置参数,因此使用
xxforms:default
而不是calculate
。calculate
将在每次 XForms 重新计算时进行计算,并且会失败,因为xxforms:get-request-parameter()
仅在 XForms 初始化期间可用。您可以在 XPath 中实现该条件。
如果参数丢失,
xxforms:get-request-parameter()
返回空序列。这应该有效:它的作用是,如果 xxforms:get-request-parameter() 返回空序列,则序列的第一个值将为“false”,这就是将使用的值设置值。
You probably want to set the parameter upon initialization only, so use
xxforms:default
instead ofcalculate
.calculate
will be evaluated at each XForms recalculate, and that will fail becausexxforms:get-request-parameter()
is only available during XForms initialization.You can implement the condition in XPath.
xxforms:get-request-parameter()
returns and empty sequence if the parameter is missing. This should work:What this does is that if
xxforms:get-request-parameter()
returns an empty sequence, then the first value of the sequence will be 'false', and that's what will be used to set the value.