[英]FLEX: Dynamically accessing multiple datagrids by passing caller object ids to a function
SOLVED 解决了
I have a Flex/PHP app I'm working on. 我有一个正在使用的Flex / PHP应用程序。
I have a single ArrayCollection for a data source, but have 8 datagrids (named dg1 through dg8). 我有一个用于数据源的ArrayCollection,但是有8个数据网格(名为dg1至dg8)。 I use 8 datagrids for logical presentation (4 years of college, 2 semesters per year).
我使用8个数据网格进行逻辑表示(4年制大学,每年2个学期)。 I have a column with "X" (for "delete this record") that goes to a function when clicked.
我有一列带有“ X”(用于“删除此记录”)的列,当单击该列时该列会转到函数。
What I'd like to do is pass the datagrid id (such as "dg1") and the data provider {syllabus.freshFall} to a function. 我想做的是将datagrid id(例如“ dg1”)和数据提供者{syllabus.freshFall}传递给一个函数。 I've been trying my hardest to find how I do this, but have only found examples of single datagrids (which look pretty easy) and referring to a single fixed datagrid like this:
我一直在尽力找到如何做到这一点的方法,但只找到了单个数据网格的示例(看起来很简单),并引用了一个固定的数据网格,例如:
course_id=dg1.selectedItem.course_ID;
syllabus.freshFall.removeItemAt(dg1.selectedIndex);
I want to make this something like this: 我想做这样的事情:
course_id=**whateverDataGrid**.selectedItem.course_ID;
**whateverDataProvider**.removeItemAt(**whateverDataGrid**.selectedIndex);
NOW I need help passing my c_id variable to my HTTPService. 现在,我需要将c_id变量传递给HTTPService的帮助。
Thanks for ALL your help! 感谢你的帮助!
PARTIAL ANSWER: 部分答案:
with help from Adobe LiveDocs for Flex 3 在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
I would still like to make the data provider more of a variable, just to be complete. 我仍然想使数据提供者更多地是一个变量,仅此而已。 I tried several different approaches and the case statements were the closest to what I wanted and it worked for now.
我尝试了几种不同的方法和case语句是最接近我想要的东西和它的工作现在。
Figured out passing my c_id variable from my function to my HTTPService. 弄清楚了将c_id变量从函数传递到HTTPService。 Not exactly as straight-forward as I would have hoped...
不像我希望的那样简单明了...
Build a variable in the type of Object Add an element to the object of the name of your variable you want to pass Add a value for the variable. 以“对象”类型构建变量将元素传递给要传递的变量名称的对象。为变量添加值。 Pass the
通过
It looks like this: 看起来像这样:
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>
Hope this helps someone else. 希望这对其他人有帮助。 It's been a bit of a pain to piece this all together.
将所有内容拼凑在一起有点痛苦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.