我對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>
好像你沒在的itemRenderer實現一些狀態。試試從DataGridItemRenderer類擴展你的itemRenderer類 – Anton 2014-12-05 18:37:30