开发者

Flex CheckBox ItemRenderer Not Tied to Object?

开发者 https://www.devze.com 2023-03-12 20:55 出处:网络
I have an Actionscript class we\'ll call Person to make the example easy. I want to have a DataGrid populated with Person objects that has columns displaying things like Name, Birthday, etc. All that

I have an Actionscript class we'll call Person to make the example easy. I want to have a DataGrid populated with Person objects that has columns displaying things like Name, Birthday, etc. All that is nice and simple, but I would also like to add a checkbox column to select certain people in the DataGrid. An example use case would be as follows:

  1. Display all people.
  2. User checks a box next to each person indicating they want some action taken on those selections.
  3. Some action is taken on the user selections when the user clicks a button.

It seems like the common solution to this is to make a Selected property on each Person object, b开发者_如何学Gout that isn't really a good option for me. The Person object is used throughout the application, and it seems very unclean to have a Selected property which really isn't a concern of the Person class.

I like the type safety of having hard classes like Person, but I don't know how to solve this seemingly simple problem so I can loop through the objects and determine if the person is selected or not. Any tips on how to go about doing this? Thanks in advance.


I think you already have your answer:

It seems like the common solution to this is to make a Selected property on each Person object, but that isn't really a good option for me. The Person object is used throughout the application, and it seems very unclean to have a Selected property which really isn't a concern of the Person class.

The purpose of your "Person object" is to hold the state for one single entity (Person). In this case, 'selected' is a perfectly valid value to add because it relates to the 'state' of that person in relation to your app.

I can think of other ways to do it; but they all add complexity which I feel is needless in this case.

0

精彩评论

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