我想在flex中做统计。当我点击一个按钮时,我已经从java服务恢复了我的数组列表,当我在java中测试列表的返回值时,我恢复了统计的结束和完成日期,它给出了正确的结果但是在flex中数据网格不是填补。
这是flex中的方法:
[Bindable]
private var FinalResult:ArrayCollection = new ArrayCollection();
private function getTicketByStatus(evt:ResultEvent):void
{
FinalResult= evt.result as ArrayCollection;
dg.dataProvider=FinalResult;
}
protected function buttnSta_clickHandler(event:MouseEvent):void
{
startDate=StartDateField.selectedDate;
endDate=EndDateField.selectedDate;
CountTicketsByStatusResult.token = ticketServiceImpl.CountTicketsByStatus(startDate,endDate);
FinalResult=CountTicketsByStatusResult.lastResult;
dg.dataProvider=FinalResult;
for(var i=0;i<FinalResult.length;i++)
{
Alert.show("element"+FinalResult.length.toString());
}
}
<mx:DataGrid id="dg" x="306" y="91" width="354" height="208" dataProvider="{FinalResult}">
答案 0 :(得分:1)
您正在调用的服务调用是异步的。这意味着您在调用服务后无法立即从“lastResult”获取结果。您需要将响应者添加到返回的令牌中。
此外,由于您已经绑定到datagrid上的FinalResult arraycollection,因此您无需在getTicketByStatus方法中再次设置它。
最后要提到的一点是:私有变量按照约定以下划线为前缀,并以小写字母开头。所以FinalResult变成_finalResult。
您的代码应如下所示:
[Bindable]
private var _finalResult:ArrayCollection = new ArrayCollection();
private function getTicketByStatus(evt:ResultEvent):void
{
_finalResult = evt.result as ArrayCollection;
}
private function getTicket_faultHandler(evt:FaultEvent):void
{
// error
}
protected function buttnSta_clickHandler(event:MouseEvent):void
{
startDate=StartDateField.selectedDate;
endDate=EndDateField.selectedDate;
var token:AsyncToken = ticketServiceImpl.CountTicketsByStatus(startDate,endDate);
token.addResponder(new Responder(getTicketByStatus, getTicket_faultHandler));
}
答案 1 :(得分:0)
我添加了警报以测试我的代码,但是当我点击按钮时,视图显示为bloqued这是新代码并且没有出现警报
[Bindable]
var startDate:Date;
[Bindable]
var endDate:Date;
[Bindable]
private var final_result:ArrayCollection;
public function getTicketByStatus(evt:ResultEvent):void
{ Alert.show("1");
final_result= evt.result as ArrayCollection;
dg.dataProvider=final_result;
}
protected function button1_clickHandler(event:MouseEvent):void
{
startDate=StartDateField.selectedDate;
endDate=EndDateField.selectedDate;
CountTicketsByStatusResult.addEventListener(ResultEvent.RESULT,getTicketByStatus);
CountTicketsByStatusResult.addEventListener(FaultEvent.FAULT, onFault_handler);
CountTicketsByStatusResult.token = ticketServiceImpl.CountTicketsByStatus(startDate,endDate);
}
protected function onFault_handler(event:FaultEvent):void {
Alert.show("Error in calling service: " + event.message, "Error");
}
<s:NavigatorContent width="100%" height="100%" label="Tickets By status">
<mx:DateField id="StartDateField" x="112" y="10" width="151"/>
<mx:DateField id="EndDateField" x="803" y="7" width="153" />
<s:Label x="17" y="9" width="61" height="22" fontFamily="Georgia" fontWeight="bold"
text="From"/>
<s:Label x="769" y="17" width="40" height="22" fontFamily="Georgia" fontWeight="bold"
text="To"/>
<mx:PieChart id="myChart" x="288" y="355" height="212" dataProvider="{final_result}" showDataTips="true">
<mx:series>
<mx:PieSeries
field="number"
nameField="Status"
labelPosition="callout"/>
</mx:series>
</mx:PieChart>
<mx:Legend x="41" y="372" width="200" height="188" dataProvider="{final_result}"/>
<mx:DataGrid id="dg" x="293" y="153" width="420" height="189" dataProvider="{final_result}">
<mx:columns>
<mx:DataGridColumn dataField="status" headerText="Metrics"/>
<mx:DataGridColumn dataField="number" headerText="Number" />
</mx:columns>
</mx:DataGrid>
<s:Button x="434" y="61" width="133" label="Generate Statics"
click="button1_clickHandler(event)"/>
</s:NavigatorContent>