首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FLEX -将AsyncToken转换为ArrayCollection

FLEX -将AsyncToken转换为ArrayCollection
EN

Stack Overflow用户
提问于 2014-05-05 18:07:37
回答 1查看 231关注 0票数 0

我刚开始使用flex,但我似乎不能让它起作用。本质上,我有一个选择框,它的可用数据依赖于另一个组合框。

每个TreatmentTypes中有多个CategoryType。

这是我的密码:

组合框更改;更新复选框:

代码语言:javascript
复制
private function refreshAvailableTreatmentTypes():void {
        // this is the combo box
        fAccomplishment.habitatType = habitatTypeId.selectedIndex != -1 ? habitatTypeId.selectedItem as HabitatType : null; 
        // fAccompRemote is a RemoteObject
        var treatmentList:ArrayCollection = fAccompRemote.getValidTreatments(fAccompForm.accomplishment, fAccomplishment.habitatType);

        if ( fAccompForm.categoryTypes != null ) {
            // All categories are always shown. These are passed to the form on construction. 
            for each ( var currentCat:CategoryType in fAccompForm.categoryTypes ) {
                var catAdded:Boolean = false;
                /* loop through all the treatments in each Category and add them to 
                 * the available list if they meet the criteria */
                for each ( var currentTreat:TreatmentType in currentCat.treatments ) {
                    if (currentTreat.id in treatmentList || treatmentList.length == 0) {
                        if (!catAdded) {
                            // fCatsAndTreats defined as a [Bindable] private var
                            fCatsAndTreats.addItem( currentCat );
                            catAdded = true;
                        } 

                        fCatsAndTreats.addItem( currentTreat );
                    }
                }
            }
        }
    }

服务方法:

代码语言:javascript
复制
@RemotingInclude
public List<TreatmentType> getValidTreatments(Accomplishment accomp, HabitatType selectedHabitatType){
    if ( accomp == null || accomp.getGeometry() == null || accomp.getHabitatType() == null) {
        return new ArrayList<TreatmentType>();
    }

    Geometry accompGeo = accomp.getGeometry();
    List<TreatmentType> optionList = new ArrayList<TreatmentType>();
    String geomName = null;

    if ( accompGeo instanceof Point || accompGeo instanceof MultiPoint ) {
        geomName = "Point";
    } else if ( accompGeo instanceof LineString || accompGeo instanceof MultiLineString) {
        geomName = "Line";
    } else if ( accompGeo instanceof Polygon || accompGeo instanceof MultiPolygon ) {
        geomName = "Polygon";
    }

    Integer habTypeId = null;
    if (selectedHabitatType == null) {
        habTypeId = accomp.getHabitatType().getId();
    } else {
        habTypeId = selectedHabitatType.getId();
    }
    optionList = accomplishmentDao.getValidTreatments(geomName, habTypeId);

    return optionList;
}

TypeError:错误#1034:类型强制失败:无法将mx.rpc::AsyncToken@1af48641转换为mx.collections.ArrayCollection。

我该怎么做?我找到了,但它似乎对我帮助不大:如有任何资源或资料,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-05 20:38:46

对RemoteObject的调用是异步的--来自fAccompRemote.getValidTreatments的返回值是一个AsyncToken,它定义了结果(返回时)将如何处理。

当远程调用返回时,它将调用结果处理程序或故障处理程序,具体取决于调用是否成功或是否有错误。

有几种不同的方法可以为您的代码设置响应处理程序--您可以在调用时设置addEventListener,也可以在调用返回的AsyncToken中设置响应程序。

代码语言:javascript
复制
fAccompRemote.addEventListener(ResultEvent.RESULT, resultHandler);
fAccompRemote.getValidTreatments(...)

-或者-

代码语言:javascript
复制
var token:AsyncToken = fAccompRemote.getValidTreatments(...);
token.addResponder(new AsyncResponder(resultHandler, faultHandler));

在任何一种情况下,resultHandler都会收到一个ResultEvent事件,其中包含从getValidTreatments返回的ArrayCollection。

代码语言:javascript
复制
protected function resultHandler(event:ResultHandler):void
{
    var results:ArrayCollection = event.result as ArrayCollection;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23478894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档