我有一些数据想要以十进制存储,但在 s:DropDownList 中以十六进制显示。I have developed the custom renderer and the drop down list displays the numbers in hex fine, BUT when the number is selected it is displayed in decimal. 我希望将数字存储为十进制,但始终以十六进制显示,无论是在下拉列表中还是在选择时。我怎样才能做到这一点?
自定义渲染器:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:Label text="{makeLabel(data)}"/>
<fx:Script>
<![CDATA[
public function makeLabel(data:Object):String {
var x:int = data as int;
var ret:String = x.toString(16);
if (ret.length < 2) {
ret = '0' + ret;
}
return ret.toUpperCase() + 'H';
}
]]>
</fx:Script>
</s:ItemRenderer>
测试存根:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var dp:ArrayCollection = new ArrayCollection([9, 10, 11, 12]);
]]>
</fx:Script>
<s:DropDownList x="72" y="43" dataProvider="{dp}" itemRenderer="HexListRenderer"/>
</s:Application>