从动态 HTTPService 异步获取数据以填充高级数据网格 Flex

发布于 2024-08-16 04:25:36 字数 13353 浏览 10 评论 0原文

我必须填充具有以下字段的高级数据网格: 大陆->国家->社会-->实际值-->估计值 我想模拟金融市场,因此我必须通过来自 HTTPService 的异步请求来更改一些值;你有想法这样做吗? 谢谢。 如果有必要,我将发布 .as 文件,但它是由 Flex Builder 自动生成的。

以下是客户端 Flex/Air 应用程序的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"     
pageTitle="prova" 
  creationComplete="initApp()" backgroundGradientColors="[#ffffff, #ffffff]">

<mx:ViewStack id="applicationScreens" width="100%" height="100%">
    <mx:Canvas id="view" width="100%" height="100%">

    <mx:AdvancedDataGrid id="dataGrid" initialize="gc.refresh();"
        borderColor="#000000"
        selectionMode="singleRow"
        rowCount="8"
        editable="false"
        lockedColumnCount="1"
        right="10" left="10" top="10" bottom="71" itemClick="adg_itemClick(event);">
        <mx:dataProvider>
     <mx:GroupingCollection id="gc" source="{dataArr}">
         <mx:grouping>
             <mx:Grouping>
                 <mx:GroupingField name="continenteCol">
            <mx:summaries>     
          <mx:SummaryRow summaryPlacement="group">  

            <mx:fields>
              <mx:SummaryField dataField="actualCol" 
                 operation="SUM"/>
              <mx:SummaryField dataField="estimateCol" 
                 operation="SUM"/>

            </mx:fields>
          </mx:SummaryRow>
              </mx:summaries> 
                </mx:GroupingField>           
                 <mx:GroupingField name="statoCol">

          <mx:SummaryRow summaryPlacement="group">
            <mx:fields>
              <mx:SummaryField dataField="actualCol" 
                operation="SUM" />
              <mx:SummaryField dataField="estimateCol" 
                 operation="SUM"/>

            </mx:fields>
          </mx:SummaryRow>
        </mx:GroupingField>
             </mx:Grouping>
         </mx:grouping>
     </mx:GroupingCollection>
 </mx:dataProvider>
            <mx:columns>
                <mx:AdvancedDataGridColumn  resizable="false" headerText="continente" dataField="continenteCol" />
                <mx:AdvancedDataGridColumn headerText="stato" dataField="statoCol" />
                <mx:AdvancedDataGridColumn headerText="societa" dataField="societaCol" />
                <mx:AdvancedDataGridColumn headerText="actual" dataField="actualCol" />
                <mx:AdvancedDataGridColumn headerText="estimate" dataField="estimateCol" />
            </mx:columns>
    </mx:AdvancedDataGrid>


    <mx:Button id="btnAddNew" click="goToUpdate()" icon="@Embed('icons/AddRecord.png')" toolTip="Add Record" x="10" bottom="10"/>
    <mx:Button id="btnDelete" click="deleteItem()" icon="@Embed('icons/DeleteRecord.png')" toolTip="Delete Record" x="58" bottom="10"/>
    <mx:Label text="Search by continente" right="300" bottom="11"/>
    <mx:TextInput id="filterTxt" width="238" toolTip="Search by continente" enter="filterResults()" right="58" bottom="11"/>
    <mx:Button click="filterResults()" id="filterButton" icon="@Embed('icons/SearchRecord.png')" toolTip="Search by continente" right="10" bottom="10"/>

</mx:Canvas>

<mx:Canvas id="update" width="100%" height="100%">
    <mx:Form width="100%" height="80%" id="provaForm">
                <mx:FormItem label="Continente:" id="continente_form">
                    <mx:TextInput id="continenteCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Stato:" id="stato_form">
                    <mx:TextInput id="statoCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Societa:" id="societa_form">
                    <mx:TextInput id="societaCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Actual:" id="actual_form">
                    <mx:TextInput id="actualCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Estimate:" id="estimate_form">
                    <mx:TextInput id="estimateCol" text=""/>
                </mx:FormItem>
    </mx:Form>

    <mx:Button label="Save" id="btnSubmit" click="insertItem()" right="81" bottom="10"/>
    <mx:Button label="Cancel" id="btnCancel" click="goToView()" right="10" bottom="10"/>
</mx:Canvas>

</mx:ViewStack>

这是 .as 文件..

/** * ActionScript 源文件,定义 UI 逻辑和一些数据访问代码。 * 该文件使用 mx:Script 标签链接到主应用程序 MXML 文件。 * 该文件中的大部分函数由定义在中的事件处理程序调用 * MXML。 / 导入 flash.events。

导入 mx.collections.ArrayCollection; 导入 mx.controls.AdvancedDataGrid; 导入 mx.controls.Alert; 导入 mx.controls.advancedDataGridClasses.AdvancedDataGridColumn; 导入 mx.events.*; 导入 mx.managers.CursorManager; 导入 mx.rpc.AsyncToken; 导入 mx.rpc.events.FaultEvent; 导入 mx.rpc.events.ResultEvent; 导入 mx.rpc.http.HTTPService;

//包括服务器端点URL的常量定义 包括“provaconfig.as”;

/** * gateway : 这是与服务器端php代码的通信层 */ 私有 var 网关:HTTPService = new HTTPService();

/** * 数组集合保存我们在网格中使用的行 */ [可绑定] public var dataArr:ArrayCollection = new ArrayCollection();

/** * 我们排序的列。每次用户点击时都会更新 * 网格列标题。 * 参见 headerRelease="setOrder(event);"在 DataGrid 实例化中 *.mxml 文件 */ 私有 var orderColumn:Number;

/** * 数据库表中的字段列表 * 需要将响应解析为哈希值 */ private var fields:Object = { 'Continue':String, 'stato':String, 'societa':String, 'actual':Number, 'estimate':Number};

/** * 当 mxml 加载完成时执行。初始化 Rest 网关。 */ 私有函数 initApp():void {

/**
 * initialize the gateway
 * - this will take care off server communication and simple xml protocol.
 */
gateway.url = ENDPOINT_URL;
gateway.method = "POST";
gateway.useProxy = false;
gateway.resultFormat = "e4x";

/**
 * set the event handler which prevents editing of the primary key
 */
dataGrid.addEventListener(AdvancedDataGridEvent.ITEM_EDIT_BEGINNING, editCellHandler);

/**
 * set the event handler which triggers the update actions - everytime an 
 * edit operation is finished
 */

dataGrid.addEventListener(AdvancedDataGridEvent.ITEM_EDIT_END, editCellEnd);

gateway.addEventListener(ResultEvent.RESULT, resultHandler);
gateway.addEventListener(FaultEvent.FAULT, faultHandler);

fill();

}

/** * 禁止编辑主键列。 * @param e DataGridEvent 包含有关网格的行和列的详细信息 * 用户点击的位置 */ 私有函数 editCellHandler(e:AdvancedDataGridEvent):void { /** * 如果用户点击主键列,则停止编辑 */ if(e.dataField == "大陆Col") { e.preventDefault(); 返回; } }

/** * 单击“过滤器”按钮的处理程序。 * 当设置另一个过滤器时,刷新集合,并加载新数据 */ 私有函数filterResults():void { 充满(); }

/** * 当用户完成编辑条目时触发事件处理程序 * 触发“更新”服务器命令 */ 私有函数 editCellEnd(e:AdvancedDataGridEvent):void { var dsRowIndex:int = e.rowIndex; var dsFieldName:String = e.dataField; var dsColumnIndex:Number = e.columnIndex;

var vo:* = dataArr[dsRowIndex];

var col:AdvancedDataGridColumn = dataGrid.columns[dsColumnIndex];
var newvalue:String = dataGrid.itemEditorInstance[col.editorDataField];

trace("a:" + dsRowIndex + ", " + dsFieldName + ", " + dsColumnIndex);

var parameters:* =
{
    "continente": vo.continenteCol,        "stato": vo.statoCol,        "societa": vo.societaCol,        "actual": vo.actualCol,        "estimate": vo.estimateCol    }

parameters[dsFieldName.substr(0,dsFieldName.length-3)] = newvalue;

/**
 * execute the server "update" command
 */
doRequest("Update", parameters, saveItemHandler);    

}

/** *“更新”服务器命令的结果处理程序。 * 只是警告错误,或者如果没问题的话什么也不做——数据已经 * 已在网格中更新 */ 私有函数 saveItemHandler(e:Object):void { if (e.isError) { Alert.show("错误:" + e.data.error); } 别的 { }
}

/** * 数据网格的dragHeader 处理程序。当用户 * 单击数据网格中的标题列 * 更新全局orderColumn变量,刷新TableCollection * @param event DataGridEvent 有关列的详细信息 */ 私有函数 setOrder(事件:AdvancedDataGridEvent):void { orderColumn = event.columnIndex; var col:AdvancedDataGridColumn = dataGrid.columns[orderColumn]; col.sortDescending = !col.sortDescending;

event.preventDefault();
fill();

}

/** * 在“添加”状态下单击“保存”按钮的处理程序 * 收集表单中的信息并向集合中添加一个新对象 / 私有函数 insertItem():void { var 参数: = { “方法”:“插入”,“大陆”:大陆Col.text,“stato”:statoCol.text,“societa”:societaCol.text,“实际”:actualCol.text,“估计”:estimateCol.text };

/**
 * execute the server "insert" command
 */
doRequest("Insert", parameters, insertItemHandler);

}

/** * 插入调用的结果处理程序。 * 如果存在错误则提示 * 如果调用成功,则返回列表,并刷新数据 */ 私有函数 insertItemHandler(e:Object):void { if (e.isError) { Alert.show("错误:" + e.data.error); } 别的 { 去查看(); 充满(); }
}

/** * 用于刷新数据的通用实用函数 * 获取过滤和排序,然后分派新的服务器调用 * */ 私有函数 fill():void { /** * 查找订单参数 */ var desc:布尔值 = false; var orderField:String = '';

if(!isNaN(orderColumn))
{
    var col:AdvancedDataGridColumn = dataGrid.columns[orderColumn];
    desc = col.sortDescending;
    //remove the 'Col' particle
    orderField = col.dataField.substr(0,col.dataField.length-3);
}

dataGrid.enabled = false;
CursorManager.setBusyCursor();

var parameters:* =
{
    "orderField": orderField,
    "orderDirection": (desc) ? "DESC" : "ASC", 
    "filter": filterTxt.text
}
/**
 * execute the server "select" command
 */
doRequest("FindAll", parameters, fillHandler);

}

/** * 填充调用的结果处理程序。 * 如果有错误,则将其显示给用户,否则用新数据重新填充 arraycollection * / 私有函数 fillHandler(e:Object):void { if (e.isError) { Alert.show("错误:" + e.data.error); } 别的 { dataArr.removeAll(); 对于每个(var row:e.data.row 中的 XML) { var temp: = {}; for (var key:字段中的字符串) { temp[key + 'Col'] = row[key]; }

        dataArr.addItem(temp);
    }

    CursorManager.removeBusyCursor();
    dataGrid.enabled = true;
}    

}

/** * 单击列表中“删除”按钮的处理程序 * 确认操作并启动deleteClickHandler函数 */ 私有函数deleteItem():void {

if (dataGrid.selectedItem)
{
    Alert.show("Are you sure you want to delete the selected record?",
    "Confirm Delete", 3, this, deleteClickHandler);
}

}

/** * 当确认对话框的事件处理函数出现时 * 删除按钮被按下。 * 如果按下的按钮为“是”,则产品将被删除。 * @param 对象事件 * @什么也不返回 / 私有函数deleteClickHandler(事件:CloseEvent):void { if (event.detail == Alert.YES) { var vo: = dataGrid.selectedItem;

    var parameters:* =
    {
        "continente": vo.continenteCol
    }

    /**
     * execute the server "delete" command
     */
    doRequest("Delete", parameters, deleteHandler);

    setTimeout( function():void
    {
        dataGrid.destroyItemEditor();
    },
    1);
}

}

公共函数deleteHandler(e:*):void { if (e.isError) { Alert.show("错误:" + e.data.error); } 别的 { var Continente:Number = parseInt(e.data.toString(), 10); for (var index:Number = 0;index < dataArr.length;index++) { if (dataArr[index].ContinenteCol == Continente) { dataArr.removeItemAt(索引); 休息; } } }
}

/** * 反序列化xml响应 * 处理错误情况 * * @param e ResultEvent 服务器响应和有关连接的详细信息 / 公共函数反序列化(obj:,e:): { var toret:对象 = {};

toret.originalEvent = e;

if (obj.data.elements("error").length() > 0)
{
    toret.isError = true;
    toret.data = obj.data;
}
else
{
    toret.isError = false;
    toret.metadata = obj.metadata;
    toret.data = obj.data;
}

return toret;

}

/** * 网关的结果处理程序 * 反序列化结果,然后调用REAL事件处理程序 *(在doRequest函数中发出请求时设置) * * @param e ResultEvent 服务器响应和有关连接的详细信息 / 公共函数 resultHandler(e:ResultEvent):void { var topass: = deserialize(e.result, e); e.token.handler.call(null, topass); }

/** * 该连接的故障处理程序 * * @param eFaultEvent 错误对象 */ 公共函数faultHandler(e:FaultEvent):void { var errorMessage:String = "连接错误:" + e.fault.faultString; if (e.fault.faultDetail) { errorMessage += "\n\n其他详细信息: " + e.fault.faultDetail; } Alert.show(errorMessage); }

/** * 使用网关实例向服务器发出请求 * * @param method_name String 服务器调度程序中使用的方法名称 * @param参数用于在post中发送的对象名称值对 * @paramcallbackFunction 调用完成时要调用的函数 */ 公共函数 doRequest(方法名称:字符串, 参数:对象, 回调:函数):void { // 将方法添加到参数列表中 参数['方法'] = 方法名称;

gateway.request = parameters;

var call:AsyncToken = gateway.send();
call.request_params = gateway.request;

call.handler = callback;

}

/** * 当用户点击“创建”按钮时点击处理程序 * 加载“更新”画布。 */ 公共函数 goToUpdate():void { applicationScreens.selectedChild = 更新; }

/** * 加载“查看”画布。 */ 公共函数 goToView():void { applicationScreens.selectedChild = 视图; }

私有函数 adg_itemClick(e:ListEvent):void { var item:Object = AdvancedDataGrid(e.currentTarget).selectedItem; e.target.expandItem(item, !e.target.isItemOpen(item),true);

}

I have to populate an Advanced Data Grid which have the following fields:
Continent->State->Society-->Actual Value-->Estimate Value
I want to simulate a financial market so i have to change some of the values by asynchronous request from an HTTPService; have you got any idea to do so?
Thank you.
If necessary i'll post the .as file, but it is generated automatically by Flex Builder.

Here's the code of the client side Flex/Air application:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"     
pageTitle="prova" 
  creationComplete="initApp()" backgroundGradientColors="[#ffffff, #ffffff]">

<mx:ViewStack id="applicationScreens" width="100%" height="100%">
    <mx:Canvas id="view" width="100%" height="100%">

    <mx:AdvancedDataGrid id="dataGrid" initialize="gc.refresh();"
        borderColor="#000000"
        selectionMode="singleRow"
        rowCount="8"
        editable="false"
        lockedColumnCount="1"
        right="10" left="10" top="10" bottom="71" itemClick="adg_itemClick(event);">
        <mx:dataProvider>
     <mx:GroupingCollection id="gc" source="{dataArr}">
         <mx:grouping>
             <mx:Grouping>
                 <mx:GroupingField name="continenteCol">
            <mx:summaries>     
          <mx:SummaryRow summaryPlacement="group">  

            <mx:fields>
              <mx:SummaryField dataField="actualCol" 
                 operation="SUM"/>
              <mx:SummaryField dataField="estimateCol" 
                 operation="SUM"/>

            </mx:fields>
          </mx:SummaryRow>
              </mx:summaries> 
                </mx:GroupingField>           
                 <mx:GroupingField name="statoCol">

          <mx:SummaryRow summaryPlacement="group">
            <mx:fields>
              <mx:SummaryField dataField="actualCol" 
                operation="SUM" />
              <mx:SummaryField dataField="estimateCol" 
                 operation="SUM"/>

            </mx:fields>
          </mx:SummaryRow>
        </mx:GroupingField>
             </mx:Grouping>
         </mx:grouping>
     </mx:GroupingCollection>
 </mx:dataProvider>
            <mx:columns>
                <mx:AdvancedDataGridColumn  resizable="false" headerText="continente" dataField="continenteCol" />
                <mx:AdvancedDataGridColumn headerText="stato" dataField="statoCol" />
                <mx:AdvancedDataGridColumn headerText="societa" dataField="societaCol" />
                <mx:AdvancedDataGridColumn headerText="actual" dataField="actualCol" />
                <mx:AdvancedDataGridColumn headerText="estimate" dataField="estimateCol" />
            </mx:columns>
    </mx:AdvancedDataGrid>


    <mx:Button id="btnAddNew" click="goToUpdate()" icon="@Embed('icons/AddRecord.png')" toolTip="Add Record" x="10" bottom="10"/>
    <mx:Button id="btnDelete" click="deleteItem()" icon="@Embed('icons/DeleteRecord.png')" toolTip="Delete Record" x="58" bottom="10"/>
    <mx:Label text="Search by continente" right="300" bottom="11"/>
    <mx:TextInput id="filterTxt" width="238" toolTip="Search by continente" enter="filterResults()" right="58" bottom="11"/>
    <mx:Button click="filterResults()" id="filterButton" icon="@Embed('icons/SearchRecord.png')" toolTip="Search by continente" right="10" bottom="10"/>

</mx:Canvas>

<mx:Canvas id="update" width="100%" height="100%">
    <mx:Form width="100%" height="80%" id="provaForm">
                <mx:FormItem label="Continente:" id="continente_form">
                    <mx:TextInput id="continenteCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Stato:" id="stato_form">
                    <mx:TextInput id="statoCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Societa:" id="societa_form">
                    <mx:TextInput id="societaCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Actual:" id="actual_form">
                    <mx:TextInput id="actualCol" text=""/>
                </mx:FormItem>
                <mx:FormItem label="Estimate:" id="estimate_form">
                    <mx:TextInput id="estimateCol" text=""/>
                </mx:FormItem>
    </mx:Form>

    <mx:Button label="Save" id="btnSubmit" click="insertItem()" right="81" bottom="10"/>
    <mx:Button label="Cancel" id="btnCancel" click="goToView()" right="10" bottom="10"/>
</mx:Canvas>

</mx:ViewStack>

Here's the .as file..

/**
* ActionScript source file that defines the UI logic and some of the data access code.
* This file is linked into the main application MXML file using the mx:Script tag.
* Most of the functions in this file are called by event handlers defined in
* the MXML.
/
import flash.events.
;

import mx.collections.ArrayCollection;
import mx.controls.AdvancedDataGrid;
import mx.controls.Alert;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.events.*;
import mx.managers.CursorManager;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

//include the constant definition of the server endpoint URL
include "provaconfig.as";

/**
* gateway : this is the communication layer with the server side php code
*/
private var gateway:HTTPService = new HTTPService();

/**
* the array collection holds the rows that we use in the grid
*/
[Bindable]
public var dataArr:ArrayCollection = new ArrayCollection();

/**
* column that we order by. This is updated each time the users clicks on the
* grid column header.
* see headerRelease="setOrder(event);" in the DataGrid instantiation in the
* mxml file
*/
private var orderColumn:Number;

/**
* the list of fields in the database table
* needed to parse the response into hashes
*/
private var fields:Object = { 'continente':String, 'stato':String, 'societa':String, 'actual':Number, 'estimate':Number};

/**
* Executes when the mxml is completed loaded. Initialize the Rest Gateway.
*/
private function initApp():void
{

/**
 * initialize the gateway
 * - this will take care off server communication and simple xml protocol.
 */
gateway.url = ENDPOINT_URL;
gateway.method = "POST";
gateway.useProxy = false;
gateway.resultFormat = "e4x";

/**
 * set the event handler which prevents editing of the primary key
 */
dataGrid.addEventListener(AdvancedDataGridEvent.ITEM_EDIT_BEGINNING, editCellHandler);

/**
 * set the event handler which triggers the update actions - everytime an 
 * edit operation is finished
 */

dataGrid.addEventListener(AdvancedDataGridEvent.ITEM_EDIT_END, editCellEnd);

gateway.addEventListener(ResultEvent.RESULT, resultHandler);
gateway.addEventListener(FaultEvent.FAULT, faultHandler);

fill();

}

/**
* Disallow editing of the primary key column.
* @param e DataGridEvent contains details about the row and column of the grid
* where the user clicked
*/
private function editCellHandler(e:AdvancedDataGridEvent):void
{
/**
* if the user clicked on the primary key column, stop editing
*/
if(e.dataField == "continenteCol")
{
e.preventDefault();
return;
}
}

/**
* Click handler for "Filter" button.
* When setting another filter, refresh the collection, and load the new data
*/
private function filterResults():void
{
fill();
}

/**
* Event handler triggered when the user finishes editing an entry
* triggers an "update" server command
*/
private function editCellEnd(e:AdvancedDataGridEvent):void
{
var dsRowIndex:int = e.rowIndex;
var dsFieldName:String = e.dataField;
var dsColumnIndex:Number = e.columnIndex;

var vo:* = dataArr[dsRowIndex];

var col:AdvancedDataGridColumn = dataGrid.columns[dsColumnIndex];
var newvalue:String = dataGrid.itemEditorInstance[col.editorDataField];

trace("a:" + dsRowIndex + ", " + dsFieldName + ", " + dsColumnIndex);

var parameters:* =
{
    "continente": vo.continenteCol,        "stato": vo.statoCol,        "societa": vo.societaCol,        "actual": vo.actualCol,        "estimate": vo.estimateCol    }

parameters[dsFieldName.substr(0,dsFieldName.length-3)] = newvalue;

/**
 * execute the server "update" command
 */
doRequest("Update", parameters, saveItemHandler);    

}

/**
* result handler for the "update" server command.
* Just alert the error, or do nothing if it's ok - the data has already
* been updated in the grid
*/
private function saveItemHandler(e:Object):void
{
if (e.isError)
{
Alert.show("Error: " + e.data.error);
}
else
{
}
}

/**
* dragHeader handler for the datagrid. This handler is executed when the user
* clicks on a header column in the datagrid
* updates the global orderColumn variable, refreshes the TableCollection
* @param event DataGridEvent details about the column
*/
private function setOrder(event:AdvancedDataGridEvent):void
{
orderColumn = event.columnIndex;
var col:AdvancedDataGridColumn = dataGrid.columns[orderColumn];
col.sortDescending = !col.sortDescending;

event.preventDefault();
fill();

}

/**
* Click handler for the "Save" button in the "Add" state
* collects the information in the form and adds a new object to the collection
/
private function insertItem():void {
var parameters:
=
{
"method": "Insert", "continente": continenteCol.text, "stato": statoCol.text, "societa": societaCol.text, "actual": actualCol.text, "estimate": estimateCol.text };

/**
 * execute the server "insert" command
 */
doRequest("Insert", parameters, insertItemHandler);

}

/**
* Result handler for the insert call.
* Alert the error if it exists
* if the call went through ok, return to the list, and refresh the data
*/
private function insertItemHandler(e:Object):void
{
if (e.isError)
{
Alert.show("Error: " + e.data.error);
}
else
{
goToView();
fill();
}
}

/**
* general utility function for refreshing the data
* gets the filtering and ordering, then dispatches a new server call
*
*/
private function fill():void
{
/**
* find the order parameters
*/
var desc:Boolean = false;
var orderField:String = '';

if(!isNaN(orderColumn))
{
    var col:AdvancedDataGridColumn = dataGrid.columns[orderColumn];
    desc = col.sortDescending;
    //remove the 'Col' particle
    orderField = col.dataField.substr(0,col.dataField.length-3);
}

dataGrid.enabled = false;
CursorManager.setBusyCursor();

var parameters:* =
{
    "orderField": orderField,
    "orderDirection": (desc) ? "DESC" : "ASC", 
    "filter": filterTxt.text
}
/**
 * execute the server "select" command
 */
doRequest("FindAll", parameters, fillHandler);

}

/**
* result handler for the fill call.
* if it is an error, show it to the user, else refill the arraycollection with the new data
*
/
private function fillHandler(e:Object):void
{
if (e.isError)
{
Alert.show("Error: " + e.data.error);
}
else
{
dataArr.removeAll();
for each(var row:XML in e.data.row)
{
var temp:
= {};
for (var key:String in fields)
{
temp[key + 'Col'] = row[key];
}

        dataArr.addItem(temp);
    }

    CursorManager.removeBusyCursor();
    dataGrid.enabled = true;
}    

}

/**
* Click handler for the "delete" button in the list
* confirms the action and launches the deleteClickHandler function
*/
private function deleteItem():void {

if (dataGrid.selectedItem)
{
    Alert.show("Are you sure you want to delete the selected record?",
    "Confirm Delete", 3, this, deleteClickHandler);
}

}

/**
* Event handler function for the Confirm dialog raises when the
* Delete button is pressed.
* If the pressed button was Yes, then the product is deleted.
* @param object event
* @return nothing
/
private function deleteClickHandler(event:CloseEvent):void
{
if (event.detail == Alert.YES)
{
var vo:
= dataGrid.selectedItem;

    var parameters:* =
    {
        "continente": vo.continenteCol
    }

    /**
     * execute the server "delete" command
     */
    doRequest("Delete", parameters, deleteHandler);

    setTimeout( function():void
    {
        dataGrid.destroyItemEditor();
    },
    1);
}

}

public function deleteHandler(e:*):void
{
if (e.isError)
{
Alert.show("Error: " + e.data.error);
}
else
{
var continente:Number = parseInt(e.data.toString(), 10);
for (var index:Number = 0; index < dataArr.length; index++)
{
if (dataArr[index].continenteCol == continente)
{
dataArr.removeItemAt(index);
break;
}
}
}
}

/**
* deserializes the xml response
* handles error cases
*
* @param e ResultEvent the server response and details about the connection
/
public function deserialize(obj:
, e:):
{
var toret:Object = {};

toret.originalEvent = e;

if (obj.data.elements("error").length() > 0)
{
    toret.isError = true;
    toret.data = obj.data;
}
else
{
    toret.isError = false;
    toret.metadata = obj.metadata;
    toret.data = obj.data;
}

return toret;

}

/**
* result handler for the gateway
* deserializes the result, and then calls the REAL event handler
* (set when making a request in the doRequest function)
*
* @param e ResultEvent the server response and details about the connection
/
public function resultHandler(e:ResultEvent):void
{
var topass:
= deserialize(e.result, e);
e.token.handler.call(null, topass);
}

/**
* fault handler for this connection
*
* @param e FaultEvent the error object
*/
public function faultHandler(e:FaultEvent):void
{
var errorMessage:String = "Connection error: " + e.fault.faultString;
if (e.fault.faultDetail)
{
errorMessage += "\n\nAdditional detail: " + e.fault.faultDetail;
}
Alert.show(errorMessage);
}

/**
* makes a request to the server using the gateway instance
*
* @param method_name String the method name used in the server dispathcer
* @param parameters Object name value pairs for sending in post
* @param callback Function function to be called when the call completes
*/
public function doRequest(method_name:String, parameters:Object, callback:Function):void
{
// add the method to the parameters list
parameters['method'] = method_name;

gateway.request = parameters;

var call:AsyncToken = gateway.send();
call.request_params = gateway.request;

call.handler = callback;

}

/**
* Click handler when the user click the "Create" button
* Load the "Update" canvas.
*/
public function goToUpdate():void
{
applicationScreens.selectedChild = update;
}

/**
* Load the "View" canvas.
*/
public function goToView():void
{
applicationScreens.selectedChild = view;
}

private function adg_itemClick(e:ListEvent):void
{
var item:Object = AdvancedDataGrid(e.currentTarget).selectedItem;
e.target.expandItem(item, !e.target.isItemOpen(item),true);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温暖的光 2024-08-23 04:25:36

如果我能看到整个应用程序,可能会更容易回答,但如果我理解你的问题,这里有一个刺...我不清楚异步的重点...在某种程度上,http 是异步的。然而,如果您的目标是从应用程序服务器/数据库推送数据,那么答案会有所不同,并且涉及使用 BlazeDS/LCDS 或这些技术的 OSS 克隆之一,在这些情况下,您不使用 mx:无论如何,HttpService。这是你的意思吗?

如果没有,那么显然,您需要在 MXML 中定义一个 HttpService,并且您希望将其结果事件绑定到 ActionScript 函数,该函数在服务返回时更改您的 {dataArr} (Array、ArrayCollection??)。如果您需要它来“轮询”您的服务以进行更改,我想您可以使用 Timer 对象或其他东西来做到这一点,但如果这是必要的,我会考虑 LCDS。

Might be easier to answer if I could see the whole app, but here's a stab at it if I understand your question...I'm not clear on the emphasis of asynchronous...to some extent, http is async. If however what you're aiming for is a data push from an app server/database then the answer is different and involves using BlazeDS/LCDS or one of the OSS clones of those technologies and in those cases, you're not using mx:HttpService anyways. Is this what you meant?

If not, then obviously, you'll need an HttpService defined in your MXML and you'll want to have it's result event bound to an ActionScript function that changes your {dataArr} (Array, ArrayCollection??) whenever the service returns. If you need it to "poll" your service for changes, I suppose you could maybe do that with a Timer object or something, but I'd consider LCDS if this is essential.

烟燃烟灭 2024-08-23 04:25:36

我正在尝试使用与 FLEX 3 相同的内置代码。我对直接在创建的列表中更改数据(更改数据库表的内容)的方式着迷。
现在我尝试将富文本编辑器合并到某些字段中。

我正在尝试使用被调用的行(selectedItem),现在我能够获取数据 - 但面临着我无法编辑字段中的文本的问题 - (错误1009)(某些内容未实例化)我现在将尝试添加另一个步骤 - 某种编辑 - 但它不是异步的。

另一个机会是使用creationComplete将所选行的数据获取到表单中,然后使用与列表使用的功能相同的功能,即直接更新数据库。

我的应用程序在本地主机上运行,​​部署到托管服务器可能会产生一些沙箱问题?然后别无选择,只能使用 amfphp 或 ZENDamf - blazeDS

当我解决了问题

后,我会回复

I'm trying to use the same build-in code from FLEX 3. I'm fascinated about the way I can change data directly at the created list (changing the content of my database table).
Now I experiment with incorporating the rich text editor for some of the fields.

I'm trying to use a called row (selectedItem) and now I'm able to fetch the data - but is facing the problem that I can't edit the text in the field - (error 1009)(Something is not instantiated) I will now try to put another step in - some kind of edit - but its not async.

Another opportunity could be using a creationComplete to get the data for the selected row into a form, and then use the same functionality as the list uses.i.e updating the database directly.

My application is running on a local host, deploying to a hosted server may create some sandbox issues? and then there is no way but to use amfphp or ZENDamf - blazeDS

I'll revert when I have sorted out the problem

regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文