I am trying to set the selected value of a checkbox from a dataprovider (an xml file).
<mx:DataGridColumn width="75" headerText="show/hide" dataField="@hidden">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox selected="{data.@hidden}" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
The problem I am having is, I think, that it's not recognizing the attribute in the html as boolean "hidden="false" or hidden="true". I can get the value, but开发者_JAVA技巧 how to I make it recognize the value as something other than a string?
I think you can wrap it in the type {Boolean(data.@hidden)}
An alternative if wrapping it doesn't work you can declare a boolean
var myBool:Boolean = new Boolean();
And then do a determination:
myBool = (data.@hidden=="true");
EDIT I don't have much of your code so I can't really test this but I think it should work.
create an MXML component based on the checkbox with this, for my example it will be called ItemRendCheckBox:
<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
override public function set data( value:Object ):void{
super.data = value;
this.selected = Boolean(data);
}
]]>
</mx:Script>
</mx:CheckBox>
Then in your dataGrid XML do this:
<mx:DataGridColumn width="75" headerText="show/hide" dataField="@hidden">
<mx:itemRenderer>
<mx:Component>
<mx:ItemRendCheckBox/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
I had a similar problem, to get around this just drop this code snippet into your curly brackets:
('false' == data.@hidden) ? false : true
Basically the value you're going to get from data.@hidden will not be a boolean, but a string, hence the use of the quotation marks around false.
精彩评论