gpt4 book ai didi

apache-flex - 将对象从 ArrayCollection 转换为我的自定义类的实例时出现问题

转载 作者:行者123 更新时间:2023-12-02 00:35:24 25 4
gpt4 key购买 nike

我正在使用 Flex 4,但出于某种原因我无法使以下代码正常工作,该代码发生在 dataGrid 的 ListEvent 处理程序内部:

_tempRule = DataGrid(event.currentTarget).selectedItem as Rule;

Rule是一个自定义类,上面的代码总是返回null。数据网格的数据提供者是一个 ArrayCollection。如果我尝试将上面的代码包装成如下所示:

DataGrid(event.currentTarget).selectedItem as Rule

我收到这个错误:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@e15a971 to com.mycompany.arcc.business.Rule

现在我知道我之前已经使用 native Flex 类(如 Button 等)完成了此操作,但在我的情况下它不会起作用。

这是规则类:

    package com.mycompaany.arcc.business
{
import flash.utils.describeType;

import mx.collections.ArrayCollection;

[Bindable]
public class Rule extends Object
{
public static const RANGE:String = "Range";
public static const SINGLE:String = "Single";
public static const LIST:String = "List";

/*name of the rule*/
private var _name:String;

/*rule group, like a radio group, only 1 rule from a group can be selected*/
private var _group:String;

/*Description of the group for the rule*/
private var _groupDescription:String;

/*Description of the rule*/
private var _description:String;

/*arry of values for this rule, based on the control type*/
private var _values:ArrayCollection;

/*min num of values*/
private var _numValues:int;

/*type of control to build, if range, 2 inputs, single, 1 , list 1 or more*/
private var _type:String;

public function Rule(name:String=null, group:String=null, description:String=null, values:ArrayCollection=null, numValues:int=0, type:String=null)
{
super();
_values = new ArrayCollection();

this._name = name
this._group = group;
this._description = description;
if (values)
{
this._values = values;
}
this._numValues = numValues;
this._type = type;
}


}
}

那我错过了什么?

最佳答案

快速简便的解决方案是在自定义类的顶部添加 [RemoteClass] 元标记。我在 Adob​​e 的网站上找到了这个解决方案,livedocs.adobe.com/flex/3/html/….似乎在基于列表的组件之间使用 native 拖放功能会导致自定义类在复制过程中丢失其类型。感谢大家的协助。

关于apache-flex - 将对象从 ArrayCollection 转换为我的自定义类的实例时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4824604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com