【问题标题】:Flex tree expand and collapseFlex 树展开和折叠
【发布时间】:2012-08-24 02:14:09
【问题描述】:

我创建了一个带有自定义 treeitemrenderer 的树,我在每个标签旁边添加了一个文本输入框。我的数据提供者是ArrayCollection

当我在输入框中输入值时,我可以在使用披露箭头展开或折叠树时看到该值。当我尝试从mxml 页面展开和折叠树时,出现一个奇怪的问题,单击按钮以使用以下代码展开和折叠树。

问题是当我展开或折叠树时,我在输入框中输入的值似乎在移动。

例如,我在输入框1输入了15,当我展开折叠树时,15移动到另一个输入框,然后移动到另一个输入框,然后随着我不断展开和折叠,它又回到输入的地方那个树。我还在学习 Flex。我不确定发生了什么,这与arraycollection 有关。

任何帮助将不胜感激。谢谢。

private function expandTree():void{ 
  for (var i:int = 0; i < thisTree.dataProvider.length; i ++){ 
     thisTree.expandChildrenOf(thisTree.dataProvider[i], true) 
  } 
} 

private function collapseTree():void{ 
  for (var i:int = 0; i < thisTree.dataProvider.length; i ++){ 
       thisTree.expandChildrenOf(thisTree.dataProvider[i], false) 
  } 
} 

【问题讨论】:

    标签: apache-flex tree


    【解决方案1】:

    Flex 项目渲染器被回收,这就是导致您的数据像这样移动的原因。在您的项目渲染器中,我通常发现将您的数​​据转换为可绑定的值对象并覆盖数据的设置器很有用。

    [Bindable]
    private var myBindableValueObject:MyBindableValueObject;
    
    override public function set data(v:Object):void
    {
        if(v == data)
            return;
        myBindableValueObject = v as MyBindableValueObject;
        super.data = value;
        validateNow();
    }
    

    您需要将文本输入和标签的属性绑定到值对象中的值。这将确保在适当的位置显示正确的值。使用这种方法应该可以消除您遇到的异常情况。

    【讨论】:

      【解决方案2】:

      我按照您的建议进行了尝试,但没有看到任何变化。不确定我是否能够遵循您的建议。这是代码。谢谢。

      package
      { 
          import mx.collections.*;
          import mx.controls.Label;
          import mx.controls.TextInput;
          import mx.controls.listClasses.*;
          import mx.controls.treeClasses.*;
      
          [Bindable] 
          public class TestSetupTreeItemRenderer extends TreeItemRenderer {
      
              [Bindable]
              public var _numQuestion:TextInput;
              private var _numOfQuestionText:Label;
              private var _listData:TreeListData;
              [Bindable]
              public var tItem:TestSetupTreeItem;
      
              public function TestSetupTreeItemRenderer():void {
                  super();
                  mouseEnabled = false;                        
              }
      
              override protected function createChildren():void {
                  super.createChildren();
                  _numQuestion = new TextInput();
                  _numQuestion.text = "0"; //default
      
                  _numQuestion.width = 45;
                  _numQuestion.height = 20;                        
                  _numQuestion.restrict = "0123456789";
                  addChild(_numQuestion);
      
                  _numOfQuestionText = new Label();
                  _numOfQuestionText.width = 60;
                  _numOfQuestionText.height = 22;
                  addChild(_numOfQuestionText);
              }
      
              override public function set data(value:Object):void {           
                  if(value == data)        
                      return;
                  tItem= value as TestSetupTreeItem;  
                  super.data = value;
                  validateNow();            
              }
      
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                  super.updateDisplayList(unscaledWidth,unscaledHeight);            
                  if(super.data){                
                      tItem = super.data as TestSetupTreeItem;
                      this.label.width = 150;
                      this.label.truncateToFit(null);                          
                      this.label.multiline = true;                
                      this.label.wordWrap = true;
      
                      var tld:TreeListData = TreeListData(super.listData);
      
                      this._numOfQuestionText.text = "of " + tItem.totalQuestionCount;             
                      this._numOfQuestionText.x = 300;
                      this._numOfQuestionText.y = super.label.y;                
      
                      this._numQuestion.x = 200;
                      this._numQuestion.y = super.label.y;
                      this._numQuestion.editable = true;
      
      
                      tItem.desiredQuestionCount = this._numQuestion.text;
                  }          
              } 
           }
      }
      

      【讨论】:

      • 是的,现在它正在工作。我需要这样做。_numQuestion.text=tItem.desiredQuestionCount;而不是 updateDisplayList() 中的 tItem.desiredQuestionCount = this._numQuestion.text;谢谢。
      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 2018-01-25
      • 2011-04-02
      • 1970-01-01
      • 2015-09-05
      • 2018-12-13
      • 2013-06-06
      • 2017-11-24
      相关资源
      最近更新 更多