【问题标题】:selectionchanged event fires twice for xtype selectionselectionchanged 事件为 xtype 选择触发两次
【发布时间】:2014-04-16 10:36:48
【问题描述】:

最近我注意到在使用选择小部件 (CQ.form.Selection) 时 selectionchanged 事件会触发两次。当我从下拉列表中选择某个值时,selectionchanged 被触发一次,并且在选择完成后(即 onblur)从选择小部件中失去焦点时再次触发。

以下是对话框的结构。

<dialog jcr:primaryType="cq:Dialog" title="Test Component" xtype="panel">
    <items jcr:primaryType="cq:WidgetCollection">
        <title jcr:primaryType="cq:Widget" fieldLabel="Selection" name="./sel" type="select" xtype="selection">
            <listeners jcr:primaryType="nt:unstructured" selectionchanged="function(comp, val, isChecked) {console.log("selected");}"/>
            <options jcr:primaryType="cq:WidgetCollection">
                <opt1 jcr:primaryType="nt:unstructured" text="Option 1" value="1"/>
            <opt2 jcr:primaryType="nt:unstructured" text="Option 2" value="2"/>
            <opt3 jcr:primaryType="nt:unstructured" text="Option 3" value="3"/>
            </options>
        </title>
        <link jcr:primaryType="cq:Widget" fieldLabel="Some Text" name="./text" xtype="textfield"/>
    </items>
</dialog>

此问题仅在选择类型选择 combobox 而不是复选框和收音机时才会观察到此问题。

我执行错了吗?这种行为正常吗?如何确保 selectionchanged 事件只触发一次?

提前致谢!

P.S:我使用的是 CQ 5.5,不确定在最新版本中此行为是否相同。

【问题讨论】:

    标签: extjs aem


    【解决方案1】:

    请尝试使用 xtype 组合并使用更改事件,以确保该事件仅被触发一次。我很确定这会奏效,我在 CQ 5.6.1 中尝试过。这是文档http://dev.day.com/docs/en/cq/5-5/widgets-api/?class=CQ.Ext.form.ComboBox

    如果在Crx de /libs/cq/ui/widgets/source/widgets/form/selection.js中查看crx de /libs/cq/ui/widgets.js有两个自定义事件firecomboboxselectionChanged和FirecomboboxContentChanged,则在选择发生时触发FirecomboboBoxSelectionChanged fireComboboxContentChanged 在发生更改时被触发。现在,如果我们查看 extjs 文档,更改会在模糊发生之前触发 http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.ComboBox-event-change 所以理想情况下,这里看起来有两个单独的事件。但是,如果您查看代码,fireComboboxSelectionChanged 和 fireComboboxContentChanged 都会触发一个常见事件 this.fireEvent(CQ.form.Selection.EVENT_SELECTION_CHANGED,因此我猜该事件会被触发两次。这只是我对代码的初步猜测,我将建议您将调试点放在代码中并使用 debugClientLibs=true 来找出这是否真的是原因。我可能是错的,并且仍然是 CQ 的学习者,根据我的推理回答。所以请通过在 javascript 中调试自己来验证这一点。希望这会有所帮助。

    【讨论】:

    • 感谢您的回复。这不是为了让事情发挥作用:) 它是关于了解问题。组合可能有效,但我的问题是为什么选择会这样?以及如何在选择中解决这个问题。
    • 即使我也注意到了。在得出结论之前将再次检查可能是原因。谢谢。
    猜你喜欢
    • 2021-03-17
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多