偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

輕松實(shí)現(xiàn)Flex數(shù)據(jù)綁定

開發(fā) 后端
Flex數(shù)據(jù)綁定的概念你是否熟悉,這里向大家簡單介紹一下如何在不依賴Flex框架的情況下實(shí)現(xiàn)簡單的Flex數(shù)據(jù)綁定,希望對(duì)你有所幫助。

本文和大家重點(diǎn)討論一下如何在不依賴Flex框架的情況下實(shí)現(xiàn)簡單的Flex數(shù)據(jù)綁定問題,在Flex項(xiàng)目中,F(xiàn)lex數(shù)據(jù)綁定是非常常見的代碼編寫方式,通過這種方式,我們可以減輕很多繁瑣的數(shù)據(jù)更新工作,并解除一些不必要的耦合。

如何在不依賴Flex框架的情況下實(shí)現(xiàn)簡單的Flex數(shù)據(jù)綁定

問題

在Flex項(xiàng)目中,F(xiàn)lex數(shù)據(jù)綁定是非常常見的代碼編寫方式,通過這種方式,我們可以減輕很多繁瑣的數(shù)據(jù)更新工作,并解除一些不必要的耦合。如果你還不了解綁定,點(diǎn)擊這里查看關(guān)于Flex中綁定的視頻。

如果我們是一個(gè)純ActionScript或Flash項(xiàng)目,不想依賴體積大的Flex框架,而又想使用其中的綁定機(jī)制,該如何做呢?我們可以遵循綁定的思路,自己編寫代碼實(shí)現(xiàn)綁定的方法。這里以簡單的字符串綁定為例,說明這個(gè)過程,當(dāng)然要完整的實(shí)現(xiàn)對(duì)所有數(shù)據(jù)類型的綁定機(jī)制還是要編寫更多的代碼的,請(qǐng)參照Flex中對(duì)于綁定的實(shí)現(xiàn)。

解答

首先來看一下這個(gè)例子最終完成的Demo演示:


下面來看看是如何實(shí)現(xiàn)這套機(jī)制的,首先我們來創(chuàng)建一個(gè)可綁定的數(shù)據(jù)類,并實(shí)現(xiàn)對(duì)綁定對(duì)象的數(shù)據(jù)更新,注意主要是要用bind和unlock兩個(gè)方法來實(shí)現(xiàn)對(duì)Flex數(shù)據(jù)綁定和解除綁定:
 

  1. package{   
  2. publicclassBindableObject   
  3. {    
  4. publicvarbindProperty:*;    
  5. publicfunctionBindableObject(value:*=null):void{     
  6. bindProperty=value;    
  7. }   
  8.    
  9. publicfunctionsetproperty(p:*):void{   
  10.   bindProperty=p;    
  11.  BindManager.refresh(this);   
  12.  }    
  13. publicfunctiongetproperty():*{     
  14. returnbindProperty;    
  15. }  
  16.     
  17. publicfunctionbind(obj:*,property:String):void{     
  18. BindManager.registBindableObject(obj,property,this);    
  19. }  
  20.     
  21. publicfunctionunlock(obj:*,property:String):void{    
  22.  BindManager.unlockBindableObject(obj,property,this);   
  23.  }  
  24.  }  
  25. }  

 其中對(duì)綁定的數(shù)據(jù)更新要依賴一個(gè)manager類來實(shí)現(xiàn),參見下面的代碼:
 

  1. package{   
  2. importflash.utils.Dictionary;   
  3. publicclassBindManager {    
  4. publicstaticvarvalueDic:Dictionary=newDictionary();    
  5. publicstaticfunctionregistBindableObject(obj:*,property:String,value:BindableObject):void{     
  6. if(value.property!=null)obj[property]=value.property;     
  7. if(valueDic[value]==null){      
  8. valueDic[value]=[];     
  9. }     
  10. valueDic[value].push(newInnerBindableObject(obj,property));    
  11. }  
  12.     
  13. publicstaticfunctionunlockBindableObject(obj:*,property:String,value:BindableObject):void{     
  14. if(value!=null){      
  15. varneedCheckObjs:Array=valueDic[value];      
  16. foreach(varitem:InnerBindableObjectinneedCheckObjs){       
  17. if(obj==item.obj&&property==item.property){        
  18. varindex:int=needCheckObjs.indexOf(item);        
  19. if(index!=-1)needCheckObjs.splice(index,1);      
  20.  }      
  21. }     
  22. }    
  23. }  
  24.     
  25. publicstaticfunctionrefresh(value:BindableObject=null):void{     
  26.  
  27. if(value!=null){      
  28. varneedRefObjs:Array=valueDic[value];   
  29.      
  30. foreach(varitem:InnerBindableObjectinneedRefObjs){     
  31.   if(item.obj!=null){     
  32.    item.obj[item.property]=value.property;     
  33.   }    
  34.   }     
  35. }   
  36.  }  
  37.  }}  
  38.  
  39. classInnerBindableObject{   
  40.  
  41. publicfunctionInnerBindableObject(o:*,p:String):void{   
  42.  oobj=o;    
  43. pproperty=p;  
  44.  }   
  45. publicvarobj:*; publicvarproperty:String;  
  46.  
  47. }  
  48.  

 使用方法:

1.首先創(chuàng)建一個(gè)BindableObject

2.調(diào)取它的bind方法,綁定到要更新的對(duì)象,比如:bindExpObj.bind(main.txt1,"text");

3.在需要的時(shí)候,對(duì)數(shù)據(jù)源更新,比如:bindExpObj.property=main.stringSRC.text;

4.解除Flex數(shù)據(jù)綁定,使用unlock方法,參數(shù)與bind相同,比如:bindExpObj.unlock(main.txt1,"text");

【編輯推薦】

  1. Flex數(shù)據(jù)綁定中使用Bindable元數(shù)據(jù)標(biāo)記的三種方式
  2. Flex基礎(chǔ) 創(chuàng)建***個(gè)Flex項(xiàng)目
  3. Flex數(shù)據(jù)綁定中綁定到函數(shù)、對(duì)象和數(shù)組
  4. FlexBuilder3.0與Eclipse3.4的***結(jié)合
  5. 學(xué)習(xí)筆記 FlexBuilder2.0中如何使用基于Lists的控件 

 

責(zé)任編輯:佚名 來源: riameeting.com
相關(guān)推薦

2010-07-28 13:31:10

Flex數(shù)據(jù)綁定

2010-07-28 13:11:13

Flex數(shù)據(jù)綁定

2010-07-30 09:08:21

Flex數(shù)據(jù)綁定

2010-08-12 11:34:15

Flex數(shù)據(jù)綁定

2010-07-28 13:40:44

Flex數(shù)據(jù)綁定

2010-08-10 10:56:39

2010-08-10 13:15:36

Flex配置

2010-07-30 10:45:08

Flex數(shù)據(jù)綁定

2010-07-28 13:48:49

Flex數(shù)據(jù)綁定

2010-07-30 10:23:46

Flex數(shù)據(jù)綁定

2010-08-12 11:05:33

Flex數(shù)據(jù)綁定

2010-07-30 10:53:53

Flex數(shù)據(jù)綁定

2010-07-30 09:16:24

Flex數(shù)據(jù)綁定

2010-07-28 13:54:42

Flex數(shù)據(jù)綁定

2010-07-30 10:30:58

Flex數(shù)據(jù)綁定

2010-08-12 10:10:37

FlexMapABC

2010-08-13 14:19:44

Flex綁定機(jī)制

2010-08-06 10:15:35

Flex綁定

2010-07-27 13:13:33

Flex數(shù)據(jù)綁定

2010-07-28 13:24:20

Flex數(shù)據(jù)綁定
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)