如何根据已更改的绑定 dataProvider 内容调整 Flex 3 ComboBox 宽度?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,但这些都不适合我。我设法通过创建一个新的事件处理程序来解决这个问题。
在此事件中调用的方法只是调整 dropdown.width 属性的大小。
I encountered the same problem and neither of these worked for me. I managed to solve this by creating a new event handler
The method called in this event simply resizes the dropdown.width property.
您可能只需要调用
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.我会为
choices
添加一个 setter,并在 setter 末尾的 ComboBox 上调用validateNow()
:I would add a setter for
choices
and callvalidateNow()
on the ComboBox at the end of the setter: