2011-07-26 58 views
0

我使用PHP的PHP 4.5,ZendAMF,我读了我不需要使用HTTPService来执行我想要的操作。如何将Flex复选框数组发送到mysql服务器?

表结构:

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

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

直放站代码:

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

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

如您所见,在上面的Repeater代码中,复选框作为属性标签。但是,当我将dept_Array(类型ArrayCollection)发送到服务器时,前者需要包含deptID。我该怎么做?

这是我如何创建People.mxml的dept_Array发送到服务器:

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:复选框,我没有数据属性。 MX:复选框没有,但我不能在我的项目中使用MX:复选框组件。

我将不胜感激任何帮助。另外,是否有更好的方法来做到这一点?

回答

0

我解决了这个问题,使用属性automationName发送与作为chec显示的itemName相关的ID kbox标签。

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

<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> 

我知道这可能不是最好的解决办法,但我显然做这个司空见惯任务的第一人,这为我工作。

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

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函数。

0

尝试将选定的属性与getDepartmentsResult绑定到选定的状态保存:

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

您的集合迭代后得到所选部门:

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 each (var dept:Object in getDepts_array) { 
    // ... 
} 
    if (dept.selected) 
    { 
    dept_array.push(dept.label); //here I need to be able to push the ID of selected department. 
    } 

} }

+0

这是行不通的,因为首先,我的表中没有'deptSelected'字段,其次,'selected'是一个布尔属性。 我最终所做的就是像往常一样激活文档,并仔细检查整个列表。我发现一个属性可以接受一个字符串,并且我调整了一下,并使用'automationName'属性来完成我想要做的事情。 – shailenTJ

+0

'' – shailenTJ

相关问题