请选择在ActionScript刷新数据网格时, [英] Keep selection when refreshing datagrid in ActionScript

查看:134
本文介绍了请选择在ActionScript刷新数据网格时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的第一个AIR应用程序与flashbuilder - 只要你知道

I'm working on my first ever AIR application with flashbuilder - just so you know.

我已经绑定一个 MX:DataGrid的组件到的DataProvider 这是一个 MX:的HTTPService 获取与项目的XML文件。为了保持数据长达数据我投票给定的时间间隔的Web服务。

I've bound a mx:DataGrid component to a DataProvider which is a mx:HTTPService fetching an xml file with items. To keep the data up to data I'm polling the webservice on a given interval.

我的问题是,我失去当前选择的项目在我的DataGrid,当数据被更新。我试图挽救 DataGrid.selectedIndex ,并设置当数据被更新,但我不知道什么时候做?我来最接近的是恢复索引时DataGrid的 updateComplete 事件。这工作,但选择先消失,然后消失在 - 未更新很快

My problem is that I loose the currently selected item in my DataGrid when the data is updated. I've tried to save the DataGrid.selectedIndex and set when the data is updated, but I'm not sure when to do it?! The closest I've come is to restore the index when the updateComplete event of DataGrid is fired. This works, but the selection first fades away and then fades in - not updated soon enough.

那么,什么是保持选择的最佳方式是什么? (只有一次选择的项目)

So what is the best way to keep the selection? (only one selected item at a time)

而作为一个侧面的问题:有没有简便的方法的只有的更新数据时,实际上已经改变了

And as a side question: is there a convenient way to only update the data when it has actually changed?

感激的任何建议!

推荐答案

我会从最底层做起,当它改变了只更新数据的唯一方法是通过对数据的检查在服务器端看数据是否发生了变化,使实际更新之前打个电话。因此,在短期,可以使两个电话,一个用于查看是否数据已经改变,这是一个服务器端查询,并且下一个仅当返回true,其中​​更新数据

I'll start from the bottom, the only way to only update the data when it has changed is to pass a check on the data on the server side to see if data has changed and make that a call before the actual update. So in short, you make two calls, one to see if the data has changed, which is a server side query, and the next only if that returns true, which updates the data.

另外,你还可以得到更新,并将其与当前数据,且仅当该数据是不同的更新UI,但是我中有你的意思是只是做了更新调用所有的原答案的感觉,如果数据已经改变。

Alternatively, you can also get the update, and compare it to your current data, and only update the UI if that data is different, but I have a feeling you mean the former answer of only doing the update CALL at all, if the data has changed.

至于其他的解决方案,你已经保存的selectedIndex后,做到这一点你updateComplete里面:

As for the other solution, after you've saved the selectedIndex, do this inside your updateComplete:

private function yourDataGridUpdateComplete(event:FlexEvent):void{ 
    yourDataGrid.selectedIndex = yourIndex;
    yourDataGrid.validateNow();
    yourDataGrid.scrollToIndex(yourIndex);
}

这篇关于请选择在ActionScript刷新数据网格时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆