将 dataProvider 的 Array 转换为 Arraylist 时出现问题

发布于 2024-10-30 18:04:44 字数 611 浏览 4 评论 0原文

private var MealsListResult:ArrayList = new ArrayList;
protected var _data:resultData = new resultData;

private function resultHandler():void
    {   
    var Meals:Array = _data.Meals;
    MealsListResult = _data.Meals as ArrayList;
    MealDataGrid.dataProvider = Meals;
    MealListView.dataProvider = MealsListResult;
    }

这应该有效吗? MealDataGrid 正在基于数组填充,但我正在调试并且 MealsListResult 为 null。但 _data.Meals 不是,我不知道我是否错过了一些简单的东西。

我可以通过这样做来让它工作: var MealsListResult2:ArrayList = new ArrayList(Meals); 但我觉得第一个方法应该也能工作!

(当然,这里没有显示 mxml 列表和数据网格等)

private var MealsListResult:ArrayList = new ArrayList;
protected var _data:resultData = new resultData;

private function resultHandler():void
    {   
    var Meals:Array = _data.Meals;
    MealsListResult = _data.Meals as ArrayList;
    MealDataGrid.dataProvider = Meals;
    MealListView.dataProvider = MealsListResult;
    }

Should this be working? the MealDataGrid is populating based on the array, but I am debugging and MealsListResult is null. but _data.Meals is not and I dunno if I'm missing something simple.

I can get it to work by doing it like: var MealsListResult2:ArrayList = new ArrayList(Meals); but I feel as though the first method should be working as well!

(there's mxml list and datagrid and such not shown here of course)

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

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

发布评论

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

评论(1

忆离笙 2024-11-06 18:04:44

如果 _data.Meals 的运行时类型是数组,则 _data.Meals as ArrayCollection 将失败。但是,new ArrayCollection(_data.Meals as Array)将正常工作。

CMIIW
我猜你的问题是你不能使用单个对象作为 2 个或更多不同的 ui 数据提供者。

尝试使用

MealDataGrid.dataProvider = _data.Meals;
MealListView.dataProvider = ObjectUtils.clone(_data.Meals);

更新:

抱歉我错过了阅读,我虽然它是ArrayCollection。但你需要做的就是像 ArrayCollection 一样

if _data.Meals is its runtime type is an array then _data.Meals as ArrayCollection will failed. but, new ArrayCollection(_data.Meals as Array) will working fine.

CMIIW
i guess your problem is you can't use single object as 2 or more different ui dataprovider.

try to use

MealDataGrid.dataProvider = _data.Meals;
MealListView.dataProvider = ObjectUtils.clone(_data.Meals);

UPDATE:

sorry i miss readed, i though it was ArrayColletion. but all you need to do is the same like ArrayCollection

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