0
我有一個datagrid(6列),它顯示數據庫中的字符串。我試圖使用labelfunction來轉義字符串中的html特殊字符(如&,& amp等)。在datagrid列中轉義html特殊字符
我發現這個在網絡上:
protected function makeSpecialChars(item:Object,dgName:DataGridColumn):String {
var s:String = agentName.dataField;
var v:String = item.s;
return new XMLDocument(v).firstChild.nodeValue;
}
然而,當我這樣做,我得到的錯誤:無法訪問空對象引用的屬性或方法。
protected function makeSpecialChars(item:Object,agentName:DataGridColumn):String {
return new XMLDocument(item.computer_name).firstChild.nodeValue;
}
其中computer_name是這個數據網格列的數據字段:
當我改變上述這樣的代碼也能正常工作。
發佈的Datagrid代碼:
<components:DoubleClickDataGrid xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="components.*"
width="100%" height="100%"
editable="true"
focusColor="#CEDA9B"
rollOverColor="#CEDA9B"
selectionColor="#84A207"
dataProvider="{invList}"
creationComplete="doubleclickdatagrid1_creationCompleteHandler(event)"
itemEditEnd="handleInventoryEdit(event)">
<components:columns>
<mx:DataGridColumn width="120" dataField="computer_name" headerText="Computer Name" textAlign="center" labelFunction="makeSpecialChars"/>
<mx:DataGridColumn dataField="path" headerText="Path" textAlign="center" labelFunction="makeSpecialChars"/>
<mx:DataGridColumn width="110" dataField="computer_type" textAlign="center" headerText="Computer Type" />
<mx:DataGridColumn width="180" dataField="username" headerText="Username" textAlign="center" />
<mx:DataGridColumn width="90" dataField="ip_address" headerText="IP Address" textAlign="center" />
<mx:DataGridColumn width="130" dataField="mac_address" headerText="MAC Address" textAlign="center" />
<mx:DataGridColumn width="180" dataField="computer_model" headerText="Computer Model" textAlign="center" />
<mx:DataGridColumn width="70" editable="false" headerText="Actions" textAlign="center" itemRenderer="renderers.ActionRenderer" />
</components:columns>
這多工作正常,截至目前(適用的labelFunction到只有2列)。但我要在標籤功能適用於所有列。 ..
是的,我試過,太...我得到同樣的錯誤。事實上,我已經開始那樣,但由於它沒有工作,我試着用item.s ..沒有運氣:( – Lin 2011-06-10 09:32:43
在什麼行你有NPE?如果它位於'return'語句中,我是對的嗎? – Constantiner 2011-06-10 09:37:05
NPE ??我的代碼看起來就是你發佈它的方式。 ..沒什麼不同 – Lin 2011-06-10 11:37:37