1
再回到不使用一段時間後彎曲,嘗試使用數據提供器來創建表示每日高溫和低溫下一個簡單的網格將一些XML(由PHP生成)加載到數據網格在一個星期的過程中。我可以將數據顯示在我的數據網格中,但是列以隨機順序加載。 (所以週五是星期一前等來了),所以我只是想弄清楚如何具體數據分配給特定的數據域。試圖XML分配成特定的數據網格數據域
這裏的Flex代碼; (更新工作代碼。請注意,數據域只包含XML標記/的名稱或標記的這些標記內的名字)
<?xml version="1.0" encoding="utf-8"?>
<fx:Declarations>
<s:HTTPService id="weather" url="http://localhost/weather/index.php" result="weather_resultHandler(event)" fault="weather_faultHandler(event)" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
//Setup array making sure to import Array Collection
[Bindable]
public var mydata:ArrayCollection = new ArrayCollection();
protected function weather_resultHandler(event:ResultEvent):void
{
trace(event.result.weather.city);
//mydata is our array and we are adding the info to it. Show the xml file.
mydata = event.result.weather.city;
}
protected function weather_faultHandler(event:FaultEvent):void
{
//import Alert so we can use this class
Alert.show("There is a problem with the data connection");
}
]]>
</fx:Script>
<mx:DataGrid x="49" y="226" id="weatherGrid" dataProvider="{mydata}">
<mx:columns>
<mx:DataGridColumn headerText="City" dataField="name"/>
<mx:DataGridColumn width="40" headerText="High" dataField="mon.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="mon.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="tues.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="tues.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="wed.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="wed.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="thurs.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="thurs.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="fri.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="fri.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="sat.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="sat.low"/>
<mx:DataGridColumn width="40" headerText="High" dataField="sun.high"/>
<mx:DataGridColumn width="40" headerText="Low" dataField="sun.low"/>
</mx:columns>
</mx:DataGrid>
而XML生成的XML是這個; (基於評論編輯)
<?xml version="1.0" encoding="utf-8" ?><weather><city>
<name>London</name>
<mon>
<high>-2</high>
<low>-10</low>
</mon>
<tues>
<high>-1</high>
<low>-5</low>
</tues>
<wed>
<high>0</high>
<low>-2</low>
</wed>
<thurs>
<high>3</high>
<low>0</low>
</thurs>
<fri>
<high>5</high>
<low>2</low>
</fri>
<sat>
<high>8</high>
<low>4</low>
</sat>
<sun>
<high>10</high>
<low>6</low>
</sun>
</city><city>
<name>Toronto</name>
<mon>
<high>-5</high>
<low>-10</low>
</mon>
<tues>
<high>-8</high>
<low>-15</low>
</tues>
<wed>
<high>-2</high>
<low>-7</low>
</wed>
<thurs>
<high>3</high>
<low>-3</low>
</thurs>
<fri>
<high>6</high>
<low>0</low>
</fri>
<sat>
<high>7</high>
<low>3</low>
</sat>
<sun>
<high>9</high>
<low>4</low>
</sun>
</city></weather>
我得到的數據模型背後的邏輯,但不會有我的結果填充到電網出故障了同樣的問題?如果可能,我不想使用外部庫。 – echofox 2011-03-26 21:57:19
一點都不喜歡,就像我說的,你只需要在列指定的dataField的屬性將一天的名稱。外部圖書館只是爲了幫助,你可以自己做,如果需要的話。 – 2011-03-26 22:15:33
哇,我完全是得太多之一,我不認爲這會是容易的。 :P感謝您的幫助! – echofox 2011-03-26 22:42:45