在数据网格列中转义 html 特殊字符
我有一个数据网格(6 列),它显示数据库中的字符串。我正在尝试使用 labelfunction 来转义字符串中的 html 特殊字符(如 &apos、& 等)。
我在网上找到了这个:
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是此数据网格列的数据字段。
发布数据网格代码:
<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>
到目前为止,这一切工作正常(仅将标签函数应用于 2 列)..但我想将标签函数应用于所有列......
i have a datagrid (6 columns) which displays strings from the database. I am trying to use a labelfunction to escape html special characters in the string (like &apos,& etc).
I found this on the net :
protected function makeSpecialChars(item:Object,dgName:DataGridColumn):String {
var s:String = agentName.dataField;
var v:String = item.s;
return new XMLDocument(v).firstChild.nodeValue;
}
However when i do this I get the error : Cannot access a property or method of a null object reference.
This works fine when i change the above code like this :
protected function makeSpecialChars(item:Object,agentName:DataGridColumn):String {
return new XMLDocument(item.computer_name).firstChild.nodeValue;
}
where computer_name is the datafield of this datagrid column.
Posting Datagrid code :
<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>
This much is working fine as of now (applied labelfunction to only 2 columns).. But I want to apply the label function to all the columns ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用以下内容:
Try to use the following: