2014-12-05 132 views
0

我對Flex有些新鮮感,遇到了itemRenderer的問題,我無法找到解決方案。我問過一位有着豐富經驗的同事,我試過在沒有運氣的情況下搜索互聯網。
我的問題是,我有一個dataGrid,其中每列使用itemRenderer來顯示信息,出於某種原因,這導致用戶無法選擇任何dataGrid行。我認爲它必須與itemRenderer有關,因爲當我添加一個沒有itemRenderer的虛擬列時,我可以通過點擊該虛擬列來突出顯示並選擇一行,但其他列表仍然無法工作。我已經嘗試將我的代碼與其他dataGrids的代碼進行比較,並使用itemRenderer進行工作,但是我一直未能找到任何會導致我的問題的差異。有誰知道爲什麼會發生?
謝謝!flex itemrenderer防止datagrid項目選擇

我的數據網格(我想只包括什麼,我認爲應該是相關的只是爲了保持簡潔如果有人認爲需要更多的信息,請讓我知道!):

<mx:DataGrid id="servicegridUI" left="10" right="10" top="10" bottom="85" selectable="true" 
       styleName="formDataGrid" variableRowHeight="true" toolTip="Double-click to view."> 
     <mx:columns> 
      <mx:DataGridColumn headerText="ID" dataField="ID" width="175"> 
       <mx:itemRenderer> 
        <mx:Component> 
         <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off"> 
          <mx:Text height="100%" width="100%" id="id" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
          <mx:Script> 
           <![CDATA[       
            var refId:String = ""; 
            override public function set data(value:Object):void { 
             //variables for setting text are created here 
             id.htmlText = 'ID: ' + refId + '<br><font color="#666666">Service ID: ' + servId + '</font>'; 
             id.htmlText +='<br><font color="#666666">Type and Specialty: ' + type + ' - ' + specialty + '</font>'; 
            } 

            public function openDoc(event:MouseEvent):void {    
             //removed due to irrelevance 
            } 
           ]]> 
          </mx:Script> 
         </mx:HBox> 
        </mx:Component> 
       </mx:itemRenderer> 
      </mx:DataGridColumn> 
      <mx:DataGridColumn headerText="Claimant" dataField="claimantHeader" width="125"> 
       <mx:itemRenderer> 
        <mx:Component> 
         <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off"> 
          <mx:Text height="100%" width="100%" id="claimant" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
          <mx:Script> 
           <![CDATA[ 
            var refId:String = ""; 
            override public function set data(value:Object):void { 
             //variables for setting text are created here 
             claimant.htmlText = 'Claim: ' + claim + '<br><font color="#666666">Name: '+ name +'</font>'; 
             claimant.htmlText +='<br><font color="#666666">Date: '+ date+'</font>'; 
             } 

            // Opens a new browser window and loads the file 
            public function openDoc(event:MouseEvent):void {    
             //removed due to irrelevance 
            } 
           ]]> 
          </mx:Script> 
         </mx:HBox> 
        </mx:Component> 
       </mx:itemRenderer> 
      </mx:DataGridColumn> 
      <mx:DataGridColumn headerText="Status" dataField="statusHeader" width="70"> 
       <mx:itemRenderer> 
        <mx:Component> 
         <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off" > 
          <mx:Text height="100%" width="100%" id="status" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
          <mx:Script> 
           <![CDATA[    
            var refId:String = ""; 
            override public function set data(value:Object):void { 
             //variables for setting text are created here 
             status.htmlText = 'Date: ' + refDate; 
             status.htmlText += '<br><font color="#666666">Status: ' + currStatus + '</font>'; 
            } 

            // Opens a new browser window and loads the file 
            public function openDoc(event:MouseEvent):void {    
             //removed due to irrelevance 
            } 
           ]]> 
          </mx:Script> 
         </mx:HBox> 
        </mx:Component> 
       </mx:itemRenderer> 
      </mx:DataGridColumn> 
      <mx:DataGridColumn headerText="lalala" dataField="serviceID" width="50"/><!---this is the dummy column that I created and is the only one that functions properly--> 
     </mx:columns> 
    </mx:DataGrid> 
+0

好像你沒在的itemRenderer實現一些狀態。試試從DataGridItemRenderer類擴展你的itemRenderer類 – Anton 2014-12-05 18:37:30

回答

0

當你覆寫集數據功能,你需要說

super.data = value; 

它會解決你的問題。 如果你想運行完整的應用程序,這裏是根據你的代碼的例子:

<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
<mx:Script><![CDATA[ 
    import mx.collections.ArrayCollection; 
    [Bindable] 
    private var myArrayCollection:ArrayCollection = new ArrayCollection([ 
     {ID:"1",claimantHeader: "ClaimHeader1",statusHeader:"StatusHeader1", serviceID:"SID1" , servId:"1001", name:"Bikram Dangol", type:"Type 1",specialty:"Speciality 1", claim:"Claim 1", date:"12/06/2014", refDate:"11/06/2014", currStatus:"Active"}, 
     {ID:"2",claimantHeader: "ClaimHeader2",statusHeader:"StatusHeader2", serviceID:"SID2", servId:"1002", name:"Anup Dangol", type:"Type 2",specialty:"Speciality 2", claim:"Claim 2", date:"12/07/2014", refDate:"11/07/2014", currStatus:"Inactive"}, 
     {ID:"3",claimantHeader: "ClaimHeader3",statusHeader:"StatusHeader3", serviceID:"SID3", servId:"1003",name:"Lunish Yakami", type:"Type 3",specialty:"Speciality 3", claim:"Claim 3", date:"12/08/2014", refDate:"11/08/2014", currStatus:"OnHold"}, 
                      ]); 
    ]]></mx:Script> 
<mx:DataGrid id="servicegridUI" left="10" right="10" top="10" bottom="85" selectable="true" dataProvider="{myArrayCollection}" 
      styleName="formDataGrid" variableRowHeight="true" toolTip="Double-click to view."> 
    <mx:columns> 
     <mx:DataGridColumn headerText="ID" dataField="ID" width="175"> 
      <mx:itemRenderer> 
       <mx:Component> 
        <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off"> 
         <mx:Text height="100%" width="100%" id="ID" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
         <mx:Script> 
          <![CDATA[ 
          var refId:String = ""; 
          override public function set data(value:Object):void { 
           super.data = value; 
           //variables for setting text are created here 
           ID.htmlText = 'ID: ' + refId + '<br><font color="#666666">Service ID: ' + data.servId + '</font>'; 
           ID.htmlText +='<br><font color="#666666">Type and Specialty: ' + data.type + ' - ' + data.specialty + '</font>'; 
          } 

          public function openDoc(event:MouseEvent):void { 
           //removed due to irrelevance 
          } 
          ]]> 
         </mx:Script> 
        </mx:HBox> 
       </mx:Component> 
      </mx:itemRenderer> 
     </mx:DataGridColumn> 
     <mx:DataGridColumn headerText="Claimant" dataField="claimantHeader" width="125"> 
      <mx:itemRenderer> 
       <mx:Component> 
        <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off"> 
         <mx:Text height="100%" width="100%" id="claimant" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
         <mx:Script> 
          <![CDATA[ 
          var refId:String = ""; 
          override public function set data(value:Object):void { 
           super.data = value; 
           //variables for setting text are created here 
           claimant.htmlText = 'Claim: ' + data.claim + '<br><font color="#666666">Name: '+ data.name +'</font>'; 
           claimant.htmlText +='<br><font color="#666666">Date: '+ data.date+'</font>'; 
          } 

          // Opens a new browser window and loads the file 
          public function openDoc(event:MouseEvent):void { 
           //removed due to irrelevance 
          } 
          ]]> 
         </mx:Script> 
        </mx:HBox> 
       </mx:Component> 
      </mx:itemRenderer> 
     </mx:DataGridColumn> 
     <mx:DataGridColumn headerText="Status" dataField="statusHeader" width="70"> 
      <mx:itemRenderer> 
       <mx:Component> 
        <mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off" > 
         <mx:Text height="100%" width="100%" id="status" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/> 
         <mx:Script> 
          <![CDATA[ 
          var refId:String = ""; 
          override public function set data(value:Object):void { 
           super.data = value; 
           //variables for setting text are created here 
           status.htmlText = 'Date: ' + data.refDate; 
           status.htmlText += '<br><font color="#666666">Status: ' + data.currStatus + '</font>'; 
          } 

          // Opens a new browser window and loads the file 
          public function openDoc(event:MouseEvent):void { 
           //removed due to irrelevance 
          } 
          ]]> 
         </mx:Script> 
        </mx:HBox> 
       </mx:Component> 
      </mx:itemRenderer> 
     </mx:DataGridColumn> 
     <mx:DataGridColumn headerText="lalala" dataField="serviceID" width="50"/><!---this is the dummy column that I created and is the only one that functions properly--> 
    </mx:columns> 
</mx:DataGrid> 
</mx:Application> 
+0

這樣做 - 非常感謝你!這絕對是一個有價值的Flex教訓。 – 2014-12-08 13:53:51