如何根据已更改的绑定 dataProvider 内容调整 Flex 3 ComboBox 宽度? [英] How to get Flex 3 ComboBox width to adjust based on bound dataProvider contents having changed?

查看:28
本文介绍了如何根据已更改的绑定 dataProvider 内容调整 Flex 3 ComboBox 宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Flex 3 中,我在 MXML 组件中创建了一个类似于以下内容的 ComboBox:

In Flex 3, I've created a ComboBox within an MXML component similar to the following:

<mx:ComboBox id="comboBox" dataProvider="{_choices}" />

<mx:Script>
<![CDATA[
  import mx.collections.ArrayCollection;
  // etc...
  public function get choices():ArrayCollection { return _choices; }

  [Bindable]
  private var _choices:ArrayCollection =
    new ArrayCollection( [ { data: "ALL", label: "All" } ] );
  // etc...
]]>
</mx:Script>

</mx:HBox>

在父 MXML 应用程序中,我修改了choices 属性的内容:

In the parent MXML application, I'm modifying the contents of the choices property:

myComponentId.choices.removeAll();
myComponentId.choices.addItem({data: "NY", label: "New York"});
myComponentId.choices.addItem({data: "CA", label: "California"});
// etc...

绑定正在工作,因为 ComboBox 会在运行时自动获取添加的新内容,但是它不会调整其宽度.ComboBox 的初始宽度仅足以显示组件中声明的初始项All".但是,我希望并期望 ComboBox 在绑定期间自动调整大小以显示加利福尼亚",但事实并非如此.

The binding is working in that the ComboBox is automatically picking up the new contents added at runtime, however it is not adjusting its width. The initial width of the ComboBox is wide enough only to show the initial item "All" declared in the component. However, I want and would have expected the ComboBox to re-size automatically during binding to be able to show "California", but it isn't.

在向 dataProvider 添加新的更宽标签后,如何让 ComboBox 更新其宽度?谢谢!

How can I get the ComboBox to update its width after I have added new wider labels to its dataProvider? Thank you!

推荐答案

你可能只需要调用 invalidateProperties(), invalidateDisplayList(), invalidateSize() 或三者的某种组合(我自己是 flex 新手),在更改数据提供者或其内容后强制更新组件的度量.

You probably just need to call invalidateProperties(), invalidateDisplayList(), invalidateSize(), or some combination of the three (I'm something of a flex newbie myself), to force an update to the component's measurements after changing the data provider or its contents.

myComponentId.invalidateSize();
myComponentId.invalidateDisplayList();
myComponentId.invalidateProperties();

这篇关于如何根据已更改的绑定 dataProvider 内容调整 Flex 3 ComboBox 宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆