当前位置: 代码迷 >> Web前端 >> 渲染器中解决警告unable to bind to property范例
  详细解决方案

渲染器中解决警告unable to bind to property范例

热度:528   发布时间:2012-10-27 10:42:26.0
渲染器中解决警告unable to bind to property实例
1、  dd.mxml
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	creationComplete="init();"> 
  
    <mx:Script> 
        <![CDATA[
	        
	        private var xmlListObj:XMLList = new XMLList();
        
            public function init():void{
            	var xmlLen:int = xmlID.son.displayName.length();
            	for(var i:int = 0; i < 12; i++){
            	  xmlListObj += <><ok>{xmlID.son.displayName[i]}</ok></>;
            	}
            	dataGridID.dataProvider = xmlListObj;
            }
            
        ]]> 
    </mx:Script>
    
    <mx:XML id="xmlID" source="hello.xml"/>
    
        <mx:DataGrid id="dataGridID" x="400" width="300" height="500" >
                <mx:columns>
                    <mx:DataGridColumn headerText="联系人" dataField="displayName" itemRenderer="MyCheck"/>
                     <mx:DataGridColumn headerText="联系人" dataField="displayName"/>
                </mx:columns>
        </mx:DataGrid>
    
</mx:Application>







2、MyCheck.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="80" height="30">

     <mx:Script>
     	<![CDATA[
     	        /*本问题的解决方法核心就是:重写两个方法*/
                [Bindable]
                private var _data:Object;
                [Bindable]
                private var _label:String;
                
                override public function set data(value:Object):void{
                        _label = value.displayName;
                        _data = value;
                }
                
                override public function get data():Object{
                        return _data;
                }
                
     	]]>
     </mx:Script>
     
	 <mx:CheckBox label="{_label}"/>
	 
</mx:Canvas>










3、 hello.xml
<root>
  <son>
      <displayName>梅西</displayName>
	  <displayName>德米凯利斯</displayName>
	  <displayName>罗纳尔多</displayName>
	  <displayName>三块五</displayName>
	  <displayName>马塞克</displayName>
	  <displayName>来我们</displayName>
	  <displayName>大晚上</displayName>
	  <displayName>和西蒙</displayName>
	  <displayName>色温度</displayName>
	  <displayName>方文山</displayName>
	  <displayName>访问啊</displayName>
	  <displayName>过端午</displayName>
	  <displayName>瓦地方</displayName>
	  <displayName>全都是</displayName>
  </son>
</root>



  相关解决方案