问题描述
我有一个 XBL 组件,它在 JavaScript 中创建一个复选框控件.值在组件初始化期间在 javascript 中设置.组件在未在重复内使用时运行良好,但当我尝试向上或向下移动行时在重复内使用 XBL 控件不会更改状态.
I have a XBL component which creates a checkbox control in javascript. Value is set in javascript during the component initialization. Component works well when not used inside repeat but inside repeat when I try to move rows up or down XBL control doesn't change the state.
xxforms-iteration-moved 事件在被移动的行上触发,但不会在移动期间改变位置的行上触发.例如,如果我将第 3 行移动到第 2 行,则第 3 行会触发 xxforms-iteration-moved,但我想重新初始化第 2 行中的组件,并将我的状态保存在 javascript 中.
xxforms-iteration-moved event is fired on the row which is moved but doesn't fire on the row which changes position during this move. For instance, if I move row 3 to row 2 then xxforms-iteration-moved is fired on row 3 but I want to reinitialize components in row 2 as well as my state is saved in javascript.
我认为 xxforms-iteration-moved 应该在改变位置的两行上触发?这实际上是涉及两行的交换.请评论.
I think xxforms-iteration-moved should be fired on both rows which changed position? This is really a swap which involves both rows. Please comment.
我正在使用 Orbeon Form Runner
I am using Orbeon Form Runner
推荐答案
xxforms-iteration-moved
被分派到哪些组件取决于 xxforms-iteration-moved
代码> 已定义.现在,它被分派到移动的迭代内部的控件.除了 xxforms-iteration-moved
之外,您可能需要处理 xforms-enabled
事件.考虑以下示例:您从一个包含a、c、d"的列表开始.如果在 "a" 之后插入 "b",那么新的 "b" 会得到一个 xforms-enabled
,而 "c, d" 都会得到一个 xxforms-iteration-moved
.因此,通过对这两个事件做出反应,您应该能够根据需要(重新)初始化您的组件.
To what components the xxforms-iteration-moved
is dispatched is a matter of how xxforms-iteration-moved
is defined. Right now, it is dispatched to controls inside iterations that moved. What you might need is to handle the xforms-enabled
event, in addition to xxforms-iteration-moved
. Consider the following example: you start with a list with "a, c, d". If you insert "b" after "a", then the new "b" gets an xforms-enabled
and "c, d" each get a xxforms-iteration-moved
. So by reacting to both events, you should be able to (re)initialize your component as necessary.
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
<xhtml:head>
<xhtml:title>Iteration moved</xhtml:title>
<xforms:model>
<xforms:instance>
<instance>
<letter>a</letter>
<letter>c</letter>
<letter>d</letter>
<letter>e</letter>
</instance>
</xforms:instance>
</xforms:model>
</xhtml:head>
<xhtml:body>
<fr:button>
<xforms:label>Insert b</xforms:label>
<xforms:insert ev:event="DOMActivate" nodeset="letter" at="1" position="after" origin="xxforms:element('letter', 'b')"/>
</fr:button>
<fr:button>
<xforms:label>Delete c</xforms:label>
<xforms:delete ev:event="DOMActivate" nodeset="letter[. = 'c']"/>
</fr:button>
<xforms:repeat id="letter-repeat" nodeset="letter">
<xforms:output id="letter" value=".">
<xforms:message ev:event="xxforms-iteration-moved" level="modal" value="concat('xxforms-iteration-moved : ', .)"/>
<xforms:message ev:event="xforms-enabled" level="modal" value="concat('xforms-enabled : ', .)"/>
</xforms:output>
</xforms:repeat>
</xhtml:body>
</xhtml:html>
我应该补充一点,如果您希望您的组件在重复中使用(并且迟早每个组件都会使用),那么现在,由于重复在客户端的工作方式,如果您正在做一些工作来初始化xforms-enabled
上的组件,您很可能也需要在 xxforms-iteration-moved
上这样做.例如,请参见 如何在 fr:button
组件中完成.
I should add that if you expect your component to be used in a repeat (and sooner or later every component is), right now, because of how repeats work on the client side, if you are doing some work to initialize the component on xforms-enabled
, you most likely need to do that as well on xxforms-iteration-moved
. For instance, see how this is done in the fr:button
component.
这篇关于在 xxforms-iteration-moved 上重新初始化 XBL 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!