开发者

Flex 3: should I provide prepared data to my component or make it to process data before display?

开发者 https://www.devze.com 2022-12-24 09:39 出处:网络
I\'m starting to learn a little Flex just for fun and maybe to prove that I still can learn something new :) I have some idea for a project and one of its parts is a tree component which could display

I'm starting to learn a little Flex just for fun and maybe to prove that I still can learn something new :) I have some idea for a project and one of its parts is a tree component which could display data in different ways depending on configuration.

The idea

There is list of objects having properties like id, date, time, name, description. And sometimes list should be displayed like this:

  1. first level: date
  2. second level: time
  3. third level: name

and sometimes like this:

  1. first level: year
  2. second level: month
  3. third level: day
  4. fourth level: time and name

By level I mean level of nesting of course. So, we can have years, that have months, that have days, that have hours and so forth.

The problem

What could be the best way to do it? I mean, should I prepare data for different ways of nesting outside of component or even outside of flex? I can do it at web service level in C# where I plan to have database access layer and send to flex nice and ready to display XML or array of objects. But I wonder if that won't cause additional and maybe unneccessary network traffic.

I tried to hack some code in my comp开发者_JAVA技巧onent to convert my data objects into XML or ArrayCollection but I don't know enough of Flex and got stuck on elimination of duplicates or getting specific data by some key value. Usually to do such things I have STL with maps, sets and vectors and I find Flex arrays and even Dictionary a little bit confusing (I've read language reference and googled without any significant luck).

The question

So, to sum things up: should I give my tree component data prepared just for chosen type of display or should I try to do it internally inside component (or some helper class written in ActionScript)?

ADDITIONAL QUESTION

Would it be a good approach to prepare separate data models for each way of display and some converter to transfer data between them and resulting model would be binded to component as a dataProvider? Or maybe there is some other clever way to do it and my data will reorganize automagically by themselves? :)


I would favor receiving a raw stream of data from your web service and process it in various ways within the flex client (in a helper Actionscript class). Here are the advantages I see:

1) This gives a nice separation of responsibilities. E.g. the web service should know about the data but not what ways it will be displayed.

2) Faster processing and client responsiveness. Swapping views will not involve calling your web service and the Flex client will likely be faster processing the data itself than the extra web traffic

3) Increased availability. Without extra calls to your web service, there is less of a chance of a network failure.

0

精彩评论

暂无评论...
验证码 换一张
取 消