Flex 树不重新扩展
我有一个树控件,在我将一个项目放入其中(更新数据提供程序)后,我希望它保持打开状态。我尝试了很多事情,包括 这个问题的示例 我无法上班,所以我正在做一些我觉得更基本的事情。像这样:
[Bindable]
public var open:Object = new Object();
private function dropItemInTree():void{
open = myTree.openItems;
//A bunch of code that updates the DP
reopenTree();
}
public function reopenTree():void{
for each(var item:XML in open){
expandParents(item[0]);
}
}
private function expandParents(node:XML):void {
myTree.expandItem(node,true,false);
}
但即使这样,我的树也被最小化了。出了什么问题?
I have a tree control and after I drop an item in it (which updates the dataprovider) I want it to stay open. I've tried a lot of things including the example at this question which I couldn't get to work so I'm doing something I feel is even more basic. Like this:
[Bindable]
public var open:Object = new Object();
private function dropItemInTree():void{
open = myTree.openItems;
//A bunch of code that updates the DP
reopenTree();
}
public function reopenTree():void{
for each(var item:XML in open){
expandParents(item[0]);
}
}
private function expandParents(node:XML):void {
myTree.expandItem(node,true,false);
}
But even this is leaving my tree minimized. What's going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我终于明白发生了什么事。在我的 drop 函数中,我基本上重建了整个 DP。虽然几乎相同,但在 Flash 播放器内会有不同的 UID,因此 open var 中的对象不再引用 DP 中的对象。幸运的是,我的 XML 数据提供程序中有一个 ID 字段,因此我可以使用该字段在重建的 DP 中查找该对象,并最终让 ExpandItem 方法在那里工作。
所以我的重新打开函数现在看起来像这样:
So I finally figured out what was happening. In my drop function I was basically rebuilding the entire DP. While it was almost the same it would have had different UID's inside the flash player, so the objects in the open var no longer had reference the objects in the DP. Luckily there is an ID field in my XML dataprovider so using that I was able to look up the object in the rebuilt DP and finally get the expandItem method to work there.
So my re-open function now looks kind of like this:
抱歉,这是完整的解释:底部的链接提供了完整的解释以及完整的示例。
您必须使用 Tree 控件的creationComplete 事件,而不是initialize 事件,因为数据提供程序在creationComplete 事件之前尚未完全初始化且可用。
或者,
您还可以通过设置 ExpandItem() 方法来调度 itemOpen 事件,让 openItems 框指示初始打开的项目。您可以通过将 ExpandItem() 方法的第四个可选参数指定为 true 来实现此目的。 true 第四个参数使树在项目打开时调度打开事件。以下示例显示了第四个参数的用法:
默认情况下,Tree 控件在初始化时会折叠,但您可以对其进行初始化,使其展开并选择特定的节点。
树控件的参考是: http:// livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html
Sorry, here is the full explanation: The link at the bottom gives the complete explanation along with a full sample.
You must use the Tree control's creationComplete event, not the initialize event, because the data provider is not fully initialized and available until the creationComplete event.
OR
you could also get the openItems box to indicate the initial open item by setting the expandItem() method to dispatch an itemOpen event. You can do this by specifying the fourth, optional parameter of the expandItem() method to true. The true fourth parameter causes the tree to dispatch an open event when the item opens. The following example shows the use of the fourth parameter:
By default, a Tree control is collapsed when it initializes, but you can initialize it so that it is expanded with a specific node selected.
The reference for the tree control is: http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html