我对Flex有点新,遇到了itemRenderer的问题,我无法找到解决方案。我曾经问过一个有很多灵活经验的同事,我试过没有运气的互联网搜索。
我的问题是我有一个dataGrid,其中每列使用itemRenderer来显示信息,由于某种原因,这会导致用户无法选择任何dataGrid行。我认为它必须与itemRenderer有关,因为当我添加一个没有itemRenderer的虚拟列时,我能够通过单击该虚拟列来突出显示并选择一行,但其他列仍无效。我尝试将我的代码与其他dataGrids的代码与有效的itemRenderers进行比较,但我还没有找到任何可能导致我的问题的差异。有谁知道为什么会发生这种情况?
谢谢!
我的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 :(得分: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>