弹性3.5.0;数据提供者更改时更新组合框显示列表

发布于 2024-08-27 15:06:38 字数 1016 浏览 4 评论 0原文

我有两个相关的组合框(大陆和国家)。当各大洲 ComboBox 更改时,我从某个 URL 请求 XML。当我收到该 XML 时,我会更改国家/地区 ComboBox 的 DataProvider,如下所示:

public function displayCountryArray( items:XMLList ):void
        {
            this.resellersCountryLoader.alpha = 0;
            this.resellersCountry.dataProvider = items;
            this.resellersCountry.dispatchEvent( new ListEvent( ListEvent.CHANGE ) );
        }

我调度 ListEvent.CHANGE 因为我使用它来更改另一个 ComboBox,所以请忽略它(以及第一行)。

所以,我的问题是这样的:我从第一大洲选择“亚洲”,然后组合框数据得到更新(我可以看到,因为第一个项目是带有标签“23个国家”的项目)。我单击组合,然后我可以看到国家/地区。

现在,我选择“非洲”,显示第一个项目,组合框关闭,然后当我单击它时,这些国家仍然是来自亚洲的国家。无论如何,如果我单击列表中的某个项目,则列表会正确更新,而且它具有正确的信息(正如我所说,它会影响其他 ComboBoxes )。所以唯一的问题是显示列表没有更新。

在此函数中,我尝试了这些方法

  • 将 XMLList 转换为 XMLCollection 甚至 ArrayCollection

  • 添加 this.resellersCountry.invalidateDisplayList();

  • 触发 DATA_CHANGE 和 UPDATE_COMPLETE 等事件 我知道它们没有多大意义,但我有点绝望。

请注意,当我使用 3.0.0 SDK 时,这种情况没有发生。

抱歉,如果我很蠢,但弹性事件快要了我的命。

I have two related ComboBoxes ( continents, and countries ). When the continents ComboBox changes I request a XML from a certain URL. When I receive that XML i change the DataProvider for the countries ComboBox, like this:

public function displayCountryArray( items:XMLList ):void
        {
            this.resellersCountryLoader.alpha = 0;
            this.resellersCountry.dataProvider = items;
            this.resellersCountry.dispatchEvent( new ListEvent( ListEvent.CHANGE ) );
        }

I dispatch the ListEvent.CHANGE because I use it to change another ComboBox so please ignore that (and the 1st line ).

So, my problem is this: I select "ASIA" from the first continents, then the combobox DATA get's updated ( I can see that because the first ITEM is an item with the label '23 countries' ). I click the combo then I can see the countries.

NOW, I select "Africa", the first item is displayed, with the ComboBox being closed, then when I click it, the countries are still the ones from Asia. Anyway, if I click an Item in the list, then the list updates correctly, and also, it has the correct info ( as I said it affects other ComboBoxes ). SO the only problem is that the display list does not get updated.

In this function I tried these approaches

  • Converting XMLList to XMLCollection and even ArrayCollection

  • Adding this.resellersCountry.invalidateDisplayList();

  • Triggering events like DATA_CHANGE and UPDATE_COMPLETE
    I know they don't make much sense, but I got a little desperate.

Please note that when I used 3.0.0 SDK this did not happen.

Sorry if I'm stupid, but the flex events are killing me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烙印 2024-09-03 15:06:39

设置组合框下拉列表的数据提供者似乎可以解决这个问题。

this.resellersCountry.dataProvider = items;
this.resellersCountry.dropdown.dataProvider = items;

Setting the dataprovider of the comboBox' dropdown seems to fix this problem.

this.resellersCountry.dataProvider = items;
this.resellersCountry.dropdown.dataProvider = items;
夏了南城 2024-09-03 15:06:39

this.resellersCountry.dropdown.dataProvider = 项目;

有效(Flex SDK 3.5)

希望这个错误在 4.0 中得到修复

this.resellersCountry.dropdown.dataProvider = items;

works (Flex SDK 3.5)

Hope this bug fixed in 4.0

北方的韩爷 2024-09-03 15:06:39

除了 Christophe 的回答之外:

当您在 ComboBox 中使用数据绑定时,您需要使用 BindingUtils 来设置下拉列表的数据提供程序:

MXML:

<mx:ComboBox id="cb_fontFamily"
        width="100%"
        dataProvider="{ model.fontFamilies }" />

脚本:

private function init():void
{
    BindingUtils.bindSetter(updateFontFamilies, model, "fontFamilies");
}

private function updateFontFamilies(fontFamilies:ArrayCollection):void
{
    if (cb_fontFamily != null) cb_fontFamily.dropdown.dataProvider = fontFamilies;
}

感谢 Christophe 指出了正确的方向。

In addition to Christophe´s answer:

When you are using data binding in your ComboBox you need to use the BindingUtils to set the dropdown´s dataprovider:

MXML:

<mx:ComboBox id="cb_fontFamily"
        width="100%"
        dataProvider="{ model.fontFamilies }" />

Script:

private function init():void
{
    BindingUtils.bindSetter(updateFontFamilies, model, "fontFamilies");
}

private function updateFontFamilies(fontFamilies:ArrayCollection):void
{
    if (cb_fontFamily != null) cb_fontFamily.dropdown.dataProvider = fontFamilies;
}

Thanks to Christophe for pointing in the right direction.

回心转意 2024-09-03 15:06:39

Adobe 社区论坛帖子中概述的另一个解决方法是避免重新分配不同的 ArrayCollection 对象添加到 ComboBox,而是重新使用(并重新填充)原始对象:

items.removeAll();
for each (var item:* in newItems)
{
    items.addItem(item);
}

Another workaround, outlined in an Adobe Community forum post, is to avoid re-assigning a different ArrayCollection object to the ComboBox, and instead re-using (and re-populating) the original one instead:

items.removeAll();
for each (var item:* in newItems)
{
    items.addItem(item);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文