0

我正在制作自己的组件,并在其中设置外部实例的值。例如,我的主要形式有:

<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
    <!-- Main instance -->
    <xf:instance id="fr-form-instance">
        <form>
            <section-1>
                <myControl/>
            </section-1>
        </form>
    </xf:instance>
    ...

在里面myControl.xbl我有:

<xf:setvalue
  model="fr-form-model"
  ref="instance('fr-form-instance')/form/section-1/myControl"
  value="'myValue'" /> 

但不幸的是,它看不到fr-form-model(“Reference to non-existing model id: fr-form-model”)这是可以理解的,因为组件被封装并且看不到外部元素。如何引用外部实例?

4

1 回答 1

1

xxf:binding()您可以使用(另请参阅gist )写入控件绑定:

<xh:html
        xmlns:xh="http://www.w3.org/1999/xhtml"
        xmlns:xf="http://www.w3.org/2002/xforms"
        xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
        xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xh:head>
        <xf:model>
            <xf:instance>
                <value/>
            </xf:instance>
        </xf:model>
        <xbl:xbl xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">
            <xbl:binding id="fr-gaga" element="fr|gaga" xxbl:mode="binding">
                <xbl:template>
                    <xf:trigger>
                        <xf:label>Set value</xf:label>
                        <xf:setvalue event="DOMActivate" ref="xxf:binding('fr-gaga')" value="42"/>
                    </xf:trigger>
                </xbl:template>
            </xbl:binding>
        </xbl:xbl>
    </xh:head>
    <xh:body>
        <fr:gaga ref="instance()"/>
        <xf:output value="instance()"/>
    </xh:body>
</xh:html>

否则,快速而肮脏的方法是使用该xxf:instance()功能。它具有通过 XBL 组件边界的可见性。但我们不推荐它,因为它会破坏封装。

另请参阅此论坛答案

于 2014-05-01T21:49:17.080 回答