问题: 我有一个带有3个索引的手风琴,每个都包含一个组件。该组件始终是相同的(普通数据网格)。这个数据网格通过php和JSON接收他的数据。
现在,当我的手风琴的SelectedIndex发生变化时,我的数据网格中的数据应该会改变。
这是php查询:
$query = "SELECT * FROM gerecht where typeID = " . $typeId;
其中$typeId
是selectedIndex
if(isset($_POST['accIndex'])){
$typeId = mysql_real_escape_string($_POST['accIndex']);
} else {
$typeId = 1;
}
现在每当我更改accordion-index时,数据都保持不变。这是我的灵活代码:
<?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>
我猜测出错了: - php接收selectedIndex? - 或者flex不能用新数据更新数据网格吗?
答案 0 :(得分:1)
K我终于找到了解决方案。我正在使用2个httpServices,我是从第一个接收数据的alwayys,但是这个没有包含参数。所以我将它们合二为一。导致以下代码:(我还添加了所有其他组件,所以不要注意它们)
<?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.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<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
{
sendData.send();
}
protected function accItems_changeHandler(event:IndexChangedEvent):void
{
sendData.send();
}
protected function sendData_resultHandler(event:ResultEvent):void
{
var rawArray:Array;
var rawData:String = String(event.result);
rawArray = JSON.parse(rawData) as Array;
dataArray = new ArrayCollection(rawArray);
}
]]>
</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>
<s:NavigatorContent label="Bieren">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Warme dranken">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Wijnen">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Sterke dranken">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Tapas">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Platos">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Especialidades">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
<s:NavigatorContent label="Bocadillos">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
</mx:Accordion>
</s:Application>