如何发送一个Flex复选框数组到mysql服务器? [英] How to send an array of Flex checkboxes to a mysql server?

查看:167
本文介绍了如何发送一个Flex复选框数组到mysql服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FB的PHP 4.5,ZendAMF,我读到,我不需要使用HTTPService我想做的。

I am using FB for PHP 4.5, ZendAMF, and I read that I do not need to use HTTPService for what I want to do.

表结构: / p>

Table structure:

people: {pID, pName}
departments: {deptID, deptName}
people_departments: {pID, deptName}

我有一个稍微复杂的flex脚本People.mxml。在PersonAdd状态,我有一个将用于发送数据到mysql服务器的表单。在这种形式下,我有一个中继器,将为我的数据库中的每个部门创建一个复选框。当我单击添加按钮时,我要将数据插入 people_departments 表。

I have a slightly complex flex script, People.mxml. In the PersonAdd state, I have a form which will be used to send data to the mysql server. In that form , I have a repeater that will create a checkbox for every department in my database. When I click the Add button, I want to insert data into the people and people_departments tables.

中继代码:

<mx:HBox>
  <mx:Repeater id="checkBoxRepeater"
               dataProvider="{getDepartmentsResult.lastResult}">
    <s:CheckBox id="deptCB"
                label="{checkBoxRepeater.currentItem.deptName}"/>
  </mx:Repeater>
</mx:HBox>



在我的peopleService.php文件中,我将有 createPerson $ item,$ deptArray),在该函数内部,我将执行两个SQL查询。一个查询将数据插入People表,另一个将插入数据到people_departments, people_departments.pID =新插入的人的ID。

In my peopleService.php file, I will have the function createPerson(People $item,$deptArray) and inside that function, I will execute two SQL queries. One query will insert data into the People table and the other one will insert data into people_departments, with people_departments.pID = ID of newly inserted person.

可以看到,在上面的Repeater代码中,复选框作为属性标签。但是,当我将dept_Array(类型为ArrayCollection)发送到服务器时,前者需要包含deptID。

As you can see, in the Repeater code above, the checkbox as the attribute label. However, when I send the dept_Array (of type ArrayCollection) to the server, the former needs to contain deptIDs. How can I do so?

这是我在People.mxml中创建要发送到服务器的dept_Array的方法:

This is how I create the dept_Array in People.mxml to send to the server:

protected function button_clickHandler(event:MouseEvent):void
{
 var dept_array:Array=[];
 var idx:int;
 var getDepts_array:ArrayCollection=new ArrayCollection;
 getDepts_array=getDepartmentsResult.lastResult as ArrayCollection;
 var len:int=getDepts_array.length;
 for (idx=0; idx < len; idx++)
 {
  if (deptCB[idx].selected)
  {
   dept_array.push(deptCB[idx].label); //here I need to be able to push the ID of selected department.
  }
 }
}

一个s:复选框和我没有data属性。 mx:复选框,但我不能使用我的项目中的mx:复选框组件。

I am using an s:Checkbox and I do not have the data property. mx:Checkbox does but I cannot use the mx:Checkbox component in my project.

我很感激任何帮助。

推荐答案

我通过使用属性 automationName 发送与作为复选框标签显示的itemName相关的ID。

I solved the problem by using the attribute automationName to send the ID related to the itemName displayed as the checkbox label.

请注意 data 属性不存在的火花复选框。如果您使用mx:复选框,则您有数据,您可以使用它来发送链接到您的项目的ID。

Note that the data attribute does not exist for the spark checkbox. If you use the mx:Checkbox, you have data, and you can use it to send the ID linked to your item in question.

<mx:Tile id="myTile">
  <mx:Repeater id="checkBoxRepeater"
               dataProvider="{getItemsResult.lastResult}"
               startingIndex="0">
  <s:CheckBox label="{checkBoxRepeater.currentItem.myItemName}"
              id="checkbox"
              automationName="{String(checkBoxRepeater.currentItem.myItemID)}"
              change="checkbox_changeHandler(event,event.currentTarget.repeaterIndex)"/>^
  </mx:Repeater>
</mx:Tile>

我知道这可能不是最好的解决方案,但我显然是第一个做这个

I know that this may not be the best solution, but I am apparently the first person to do this commonplace task, and this worked for me.

然后,发送所选复选框的ID数组,我使用下面的代码,在我的submitBtn_clickHandler函数中定义:

And then, the send the array of the IDs of the selected checkboxes, I use the following code, defined in my submitBtn_clickHandler function:

var items_array:Array=[];
var idx:int;
var getitems_array:ArrayCollection=new ArrayCollection;
getitems_array=getItemsResult.lastResult as ArrayCollection;
var len:int=getitems_array.length;
for (idx=0; idx < len; idx++)
  {
    var element:CheckBox=myTile.getElementAt(idx) as CheckBox;
    if (element.selected)
    {
      items_array.push(element.automationName);
    }
  }

然后我通过 items_array 作为我的ItemService.createItem函数的附加参数。

I then pass items_array as an additional parameter to my ItemService.createItem function.

这篇关于如何发送一个Flex复选框数组到mysql服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆