The question:
I have an accordion with 3 index’s, each containing a component. That component is always the same one (an ordinary datagrid). This datagrid receives his data through php and JSON.
Now when the SelectedIndex of my accordeon changes, the data in my datagrid should change.
this is the php query:
$query = "SELECT * FROM gerecht where typeID = " . $typeId;
where $typeId is the selectedIndex
if(isset($_POST['accIndex'])){
$typeId = mysql_real_escape_string($_POST['accIndex']);
} else {
$typeId = 1;
}
Now whenever I change the accordion-index, the data stays the same. Here is my flex code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:components="components.*" initialize="getData.send();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:HTTPService id="getData" url="http://localhost/P006_Project/Query.php"
useProxy="false" method="POST" resultFormat="text" result="getPHPData(event)" />
<mx:HTTPService id="sendData" url="http://localhost/P006_Project/Query.php"
useProxy="false" method="POST" result="sendData_resultHandler(event)">
<mx:request xmlns="">
<accIndex>
{accItems.selectedIndex + 1}
</accIndex>
</mx:request>
</mx:HTTPService>
<s:ArrayCollection id="acItems" source="{dataArray.source}" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.Text;
import mx.events.FlexEvent;
import mx.events.IndexChangedEvent;
import mx.rpc.events.ResultEvent;
[Bindable]private var dataArray:ArrayCollection = new ArrayCollection();
private function initDataGrid():void
{
getData.send();
}
private function getPHPData(event:ResultEvent):void
{
var rawArray:Array;
var rawData:String = String(event.result);
rawArray = JSON.parse(rawData) as Array;
dataArray = new ArrayCollection(rawArray);
}
protected function accItems_changeHandler(event:IndexChangedEvent):void
{
// TODO Auto-generated method stub
sendData.send();
trace(acItems);
}
protected function sendData_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
Alert.show(event.result.toString());
}
]]>
</fx:Script>
<mx:Accordion id="accItems" creationPolicy="auto" change="accItems_changeHandler(event)">
<s:NavigatorContent label="Frisdranken">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Bieren (vat)">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
</mx:Accordion>
</s:Application>
I’m guessing something is going wrong either in:
– php receiving the selectedIndex?
– or flex is not able to update the datagrid with the new data?
K I finally found the solution. I was using 2 httpServices, I was alwayys receiving the data from the first one, but this one did not contain a parameter. So I merged both of them in one. Resulting in the following code: (I also added all of my other components so don’t pay attention to them)