1
問題: 我有一個帶有3個索引的手風琴,每個手風琴都包含一個組件。該組件總是相同的(一個普通的數據網格)。這個數據網格通過php和JSON接收他的數據。Flex Datagrid沒有更新
現在,當我的accordeon的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;
}
現在,每當我改變手風琴指數,該數據保持不變。這裏是我的Flex代碼:
<?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無法使用新數據更新數據網格?
您是否看到期望值達到'getPHPData'fn? IE'dataArray'包含它應該的內容? – ethrbunny
我'dataArray'的內容似乎一直保持不變,所以我猜selectedIndex沒有到達PHP文件? – ZackWhite
聽起來像。因此,下一步是確定價值是否正在發送。我沒有看到任何params通過。不知道這是否重要。 – ethrbunny