如何根据已更改的绑定 dataProvider 内容调整 Flex 3 ComboBox 宽度?

发布于 2024-08-05 00:35:57 字数 947 浏览 4 评论 0原文

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

<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 属性的内容:

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

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

在向其 dataProvider 添加新的更宽标签后,如何让 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>

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...

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.

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

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

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

发布评论

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

评论(3

回忆那么伤 2024-08-12 00:35:58

我遇到了同样的问题,但这些都不适合我。我设法通过创建一个新的事件处理程序来解决这个问题。

menuComboBox.addEventListener(ResizeEvent.RESIZE, updateListWidth);

在此事件中调用的方法只是调整 dropdown.width 属性的大小。

private function updateListWidth(event:ResizeEvent):void {
        menuComboBox.dropdown.width = menuComboBox.width;
}

I encountered the same problem and neither of these worked for me. I managed to solve this by creating a new event handler

menuComboBox.addEventListener(ResizeEvent.RESIZE, updateListWidth);

The method called in this event simply resizes the dropdown.width property.

private function updateListWidth(event:ResizeEvent):void {
        menuComboBox.dropdown.width = menuComboBox.width;
}
若无相欠,怎会相见 2024-08-12 00:35:57

您可能只需要调用 invalidateProperties()invalidateDisplayList()invalidateSize() 或三者的某种组合(我是我自己是一个 Flex 新手),在更改数据提供程序或其内容后强制更新组件的测量值。

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

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();
乱世争霸 2024-08-12 00:35:57

我会为 choices 添加一个 setter,并在 setter 末尾的 ComboBox 上调用 validateNow()

public function set choices(value:ArrayCollection):void
{
    _choices = value;

    comboBox.validateNow();
}

I would add a setter for choices and call validateNow() on the ComboBox at the end of the setter:

public function set choices(value:ArrayCollection):void
{
    _choices = value;

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