2011-03-28 100 views
0

我有幾個datagrids(從某些地圖服務中檢索數據)。Flex Datagrid + Tab導航器

我想將這些數據網格放置在標籤導航器的單獨選項卡中。所有的工作都很好,除了第一個標籤總是沒有任何數據網格。

我已經嘗試過創建策略=「全部」和東西,但第一個標籤總是空的。有沒有人有任何想法,爲什麼第一個標籤總是空的。

任何解決方法。

感謝

var box:HBox=new HBox(); 
var dg:DataGrid = new DataGrid(); 
dg.dataProvider = newAC; 
box.label=title.text; 
box.addChild(dg); 
tabNaviId.addChild(box); 
tabNaviId.selectedIndex=2; 
resultsArea.addChild(tabNaviId); 

DG是填充了數據網格。上面的代碼是在一個循環中,在每個循環中我創建一個Hbox +數據網格。然後我將Hbox添加到導航器中,最後將導航器添加到resultsArea(這是一個畫布)。

上面的代碼與第一次相比效果很好。

我得到的最終結果是,有一個沒有任何數據網格的第一個選項卡的選項卡導航器,但其餘選項卡都有數據網格。任何想法,爲什麼發生這種情況。

呼叫到一個名爲createDatagrid功能是由:

dgCollection.addItem(parentApplication.resultsPanel.createDatagrid(token.name.toString() + " (" + recAC.length + " selected)", recAC, false, callsToMake)); 

在另一個MXML組件此功能存在

public function createDatagrid(titleText:String, recACAll:ArrayCollection, showContent:Boolean, callsToMake:Number):DataGrid 
     { 

      var dg:DataGrid = new DataGrid(); 
      var newAC:ArrayCollection = new ArrayCollection(); 
      var newDGCols:Array = new Array(); 

      for(var i:Number = 0; i < recACAll.length; i ++) 
      { 
       var contentStr:String = recACAll[i][CONTENT_FIELD]; 
       var featureGeo:Geometry = recACAll[i][GEOMETRY_FIELD]; 
       var iconPath:String = recACAll[i][ICON_FIELD]; 
       var linkStr:String = recACAll[i][LINK_FIELD]; 
       var linkNameStr:String = recACAll[i][LINK_NAME_FIELD]; 
       var featurePoint:MapPoint = recACAll[i][POINT_FIELD]; 
       var titleStr:String = recACAll[i][TITLE_FIELD]; 

       if(contentStr.length > 0) 
       { 
        var rows:Array = contentStr.split("\n"); 

        var tmpObj:Object = new Object(); 

        if(!showContent) 
        { 
         for(var j:Number = 0; j < rows.length; j++) 
         { 
          var tmpStr:String = rows[j] as String; 
          var header:String = tmpStr.substring(0,tmpStr.indexOf(":")); 
          var val:String = tmpStr.substring(tmpStr.indexOf(":") + 2); 
          if(header.length > 0) 
          { 
           tmpObj[header] = val; 
           if(newDGCols.length < rows.length - 1) 
           { 
            newDGCols.push(new DataGridColumn(header)); 
           } 
          } 
         } 
        } 
        else 
        { 
         if(newDGCols.length == 0) 
         { 
          newDGCols.push(new DataGridColumn(CONTENT_FIELD)); 
          newDGCols.push(new DataGridColumn(GEOMETRY_FIELD)); 
          newDGCols.push(new DataGridColumn(ICON_FIELD)); 
          newDGCols.push(new DataGridColumn(LINK_FIELD)); 
          newDGCols.push(new DataGridColumn(LINK_NAME_FIELD)); 
          newDGCols.push(new DataGridColumn(POINT_FIELD)); 
          newDGCols.push(new DataGridColumn(TITLE_FIELD)); 
         } 
        } 

        tmpObj[CONTENT_FIELD] = contentStr; 
        tmpObj[GEOMETRY_FIELD] = featureGeo; 
        tmpObj[ICON_FIELD] = iconPath; 
        tmpObj[LINK_FIELD] = linkStr; 
        tmpObj[LINK_NAME_FIELD] = linkNameStr; 
        tmpObj[POINT_FIELD] = featurePoint; 
        tmpObj[TITLE_FIELD] = titleStr; 

        newAC.addItem(tmpObj); 
       } 

       if(showHidePic.source == minSourceI) 
       { 
        showHidePic.source = minSource; 
       } 
       else if(showHidePic.source == maxSourceI) 
       { 
        showHidePic.source = maxSource; 
       } 
       curResults = curResults + recACAll.length; 

       if (curResults == 1) 
       { 
        showInfoWindow(tmpObj); 

        if(showContent) 
        { 
         parentApplication.maps.map.extent = featureGeo.extent; 
        } 
       } 
       else 
       { 
        showInfoWindow(null); 
        // Added to avoid the overview button problem (needs checking) 
        this.removeEventListener(MouseEvent.MOUSE_OVER, handleMouseOver, false); 
        this.removeEventListener(MouseEvent.MOUSE_MOVE,handleMouseOver,false); 
        this.removeEventListener(MouseEvent.MOUSE_OUT,handleMouseOut,false); 
        this.removeEventListener(MouseEvent.MOUSE_DOWN,handleMouseDrag,false); 
        this.removeEventListener(MouseEvent.MOUSE_UP,handleMouseDragStop,false); 
        this.parent.removeEventListener(MouseEvent.MOUSE_MOVE,handleParentMove,false); 
        this.parent.removeEventListener(MouseEvent.MOUSE_UP,handleMouseDragStop2,false); 
        maximizePanel(); 
       } 

      } 

      dg.dataProvider = newAC; 
      dg.columns = newDGCols; 
      dg.rowCount = newAC.length; 

      var totalDGCWidth:Number = 0; 

      for(var m:Number = 0; m < dg.columns.length; m++) 
      { 
       var dgc2:DataGridColumn = dg.columns[m]; 

       /*if(dgc2.headerText.toUpperCase()==LINK_FIELD.toUpperCase()){ 

       //dgc.itemRenderer=new ClassFactory(CustomRenderer); 
       dgc2.itemRenderer=new ClassFactory(CustomRenderer); 
       }*/ 
       var dgcWidth2:Number = dgc2.headerText.length * CHAR_LENGTH; 

       for(var l:Number = 0; l < newAC.length; l++) 
       { 
        var row2:Object = newAC.getItemAt(l) as Object; 
        var rowVal2:String = row2[dgc2.headerText]; 

        if(rowVal2 != null) 
        { 
         var tmpLength2:Number = rowVal2.length * CHAR_LENGTH; 

         if(tmpLength2 < CHAR_MAX_LENGTH) 
         { 
          if(tmpLength2 > dgcWidth2) 
          { 
           dgcWidth2 = tmpLength2; 
          } 
         } 
         else 
         { 
          dgcWidth2 = CHAR_MAX_LENGTH 
          break; 
         } 
        } 

       } 
       // Added by FT:to change the item renderer for link field 


       if(dgc2.headerText == GEOMETRY_FIELD || dgc2.headerText == CONTENT_FIELD || 
        dgc2.headerText == ICON_FIELD || dgc2.headerText == LINK_FIELD || 
        dgc2.headerText == POINT_FIELD || dgc2.headerText == TITLE_FIELD || 
        dgc2.headerText == LINK_NAME_FIELD) 
       { 
        if(dgc2.headerText == CONTENT_FIELD && showContent) 
        { 
         //something 
        } 
        else 
        { 

         dgcWidth2 = 0; 
        } 
       } 

       totalDGCWidth += dgcWidth2; 
      } 

      dg.width = totalDGCWidth; 



      for(var k:Number = 0; k < dg.columns.length; k++) 
      { 
       var dgc:DataGridColumn = dg.columns[k]; 
       var dgcWidth:Number = dgc.headerText.length * CHAR_LENGTH; 
       for(var n:Number = 0; n < newAC.length; n++) 
       { 
        var row:Object = newAC.getItemAt(n) as Object; 
        var rowVal:String = row[dgc.headerText]; 

        if(rowVal != null) 
        { 
         var tmpLength:Number = rowVal.length * CHAR_LENGTH; 

         if(tmpLength < CHAR_MAX_LENGTH) 
         { 
          if(tmpLength > dgcWidth) 
          { 
           dgcWidth = tmpLength; 
          } 
         } 
         else 
         { 
          dgcWidth = CHAR_MAX_LENGTH 
          break; 
         } 
        } 

       } 
       if(dgc.headerText == GEOMETRY_FIELD || dgc.headerText == CONTENT_FIELD || 
        dgc.headerText == ICON_FIELD || dgc.headerText == LINK_FIELD || 
        dgc.headerText == POINT_FIELD || dgc.headerText == TITLE_FIELD || 
        dgc.headerText == LINK_NAME_FIELD) 
       { 
        if(dgc.headerText == CONTENT_FIELD && showContent) 
        { 
         dgc.visible = true; 
        } 
        else 
        { 

         dgc.visible = false; 
         dgcWidth = 0; 
        } 
       } 

       if(dgc.headerText == LINK_COL_NAME) 
       { 
        dgcWidth = LINK_COL_WIDTH; 
       } 

       dgc.width = dgcWidth; 
      } 

      dg.addEventListener(ListEvent.ITEM_CLICK,rowClicked); 
      dg.addEventListener(ListEvent.ITEM_ROLL_OVER,mouseOverRow); 
      dg.addEventListener(ListEvent.ITEM_ROLL_OUT,mouseOutRow); 

      var title:Text = new Text(); 
      title.text = titleText; 
      title.setStyle("fontWeight","bold"); 

      //resultsArea.addChild(title); 

      return dg; 


      //tabNaviId.selectedIndex=2;  


     } 
     public function populateGrid(dgCollection:ArrayCollection):void{ 


      for(var k:Number = 0; k < dgCollection.length; k++) 
      { 
       var box:HBox=new HBox(); 
       var dg2:DataGrid=dgCollection.getItemAt(k) as DataGrid; 
       box.label="some"; 
       box.addChild(dg2); 
       tabNaviId.addChild(box); 

      } 
      resultsArea.addChild(tabNaviId); 
     } 

和標籤導航聲明

<mx:Image id="showHidePic" click="toggleResults()"/> 
<mx:VBox y="20" styleName="ResultsArea" width="100%" height="100%"> 
    <mx:HBox> 
     <mx:Button label="Export to Excel" click="downloadExcel()"/> 
     <mx:Button label="Clear" click="clear()" /> 
    </mx:HBox> 
    <mx:VBox id="resultsArea" styleName="ResultsContent" paddingTop="10" paddingLeft="10" paddingRight="10" verticalScrollPolicy="off" horizontalScrollPolicy="off"> 
     <mx:TabNavigator id="tabNaviId" width="622" height="274" creationPolicy="all"> 

     </mx:TabNavigator> 

    </mx:VBox> 
</mx:VBox> 
+1

發佈源代碼會很有用!沒有它,我們將很難幫助你。 – sean 2011-03-28 18:01:25

+1

同意,請提供代碼,並且不要使用creationPolicy =「all」 – 2011-03-28 18:09:07

+0

謝謝你們,請看原始帖子的代碼。 – Abstract 2011-03-28 18:16:47

回答

0

摘要,可以我們得到完整的代碼,包括你提到的循環,以及你創建的代碼吃了TabNavigator?

TabNavigator有可能已經有一個初始的孩子,並且所有你正在創建的孩子正在被添加。

+0

請現在看帖子。我可以證實,數據不是問題,因爲創建的datagrid beign包含正確的數據。它只是第一個選項卡的第一個數據網格不會顯示。 – Abstract 2011-03-28 19:25:43

+0

有人可以弄清楚爲什麼第一個選項卡中的數據網格沒有被生成。 – Abstract 2011-03-29 08:17:16

+0

更新:我已經第一次使用它,但是第二次輸入到createDataGrid函數中時,該選項卡最終爲空。 – Abstract 2011-03-29 10:10:55