2011-03-22 53 views
0

動態訪問多個數據網格解決FLEX:通過傳遞調用者的對象ID的功能

我有一個Flex/PHP應用程序我的工作。

我有一個數據源的ArrayCollection,但有8個數據網格(名爲dg1到dg8)。我使用8個數據網格進行邏輯演示(4年大學,每年2個學期)。我有一個帶有「X」(用於「刪除這條記錄」)的列,當點擊這個列時,它會進入一個功能。

我想要做的是將數據網格id(如「dg1」)和數據提供者{syllabus.freshFall}傳遞給函數。我一直想我最難找到我怎麼做到這一點,但只找到一個DataGrid中的例子(這看起來很容易),並參照單一固定數據網格這樣的:

course_id=dg1.selectedItem.course_ID; 
syllabus.freshFall.removeItemAt(dg1.selectedIndex); 

我想使這個是這樣的:

course_id=**whateverDataGrid**.selectedItem.course_ID; 
**whateverDataProvider**.removeItemAt(**whateverDataGrid**.selectedIndex); 

現在我需要幫助通過我的c_id可變我的HTTPService。

感謝您的幫助!

回答

0

部分答案:

與幫助,從Adobe LiveDocs for Flex 3

<mx:LinkButton label="X" click="outerDocument.itemClickEvent('1',event)"/> 


public function itemClickEvent(id:String, event:MouseEvent):void { 
     var mydp:Object; 
     switch(int(id)) 
     { 
      case 1: 
       mydp=syllubus.freshFall; 
       break; 
           . 
           . 
          case 8: 
       mydp=syllubus.seniorSpring; 

      default: 
       trace("Out of range"); 
       break; 
     } 
     id = "dg" + id; 
     c_id=this[id].selectedItem.course_ID; 
     mydp.removeItemAt(this[id].selectedIndex); //superficial datagrid delete 

我仍想使一個變量的數據提供更多的,只是爲了完成。我嘗試了幾種不同的方法,案例陳述最接近我想要的,它現在工作

想通過我的c_id變量從我的函數傳遞給我的HTTPService。並不完全像我希望的那樣直截了當...

在對象類型中構建變量 向要傳遞的變量名稱的對象添加元素 爲變量添加一個值。 傳遞

它看起來像這樣:

function blah (var:int, ...rest):void { 

code... 

code... 

c_id= *whatever*; 
params["cid"] = c_id; 
update.send(params); (where "update" is the HttpService id) 
} 

. 
. 
. 
. 

<mx:HTTPService 
    id="update"  
    url="http://localhost/myFile.php" 
    method="POST" 
    etc...> 
<mx:request> 
    <xmlstring>{XMLString}</xmlstring> (this xml string is generated elsewhere) 
    <cid>c_id</cid> 
</mx:request> 
</mx:HTTPService> 

希望這可以幫助其他人。把所有這些都拼湊在一起是一件很痛苦的事情。