Hi Steve,
Is your problem to do with your rules about which view to display? If
it's getting a bit complicated or 'crufty', then you probably need
another level of abstraction. Encapsulate your rules about which view
should be displayed inside a getter called currentView. Bind your
view stack to this.
Now you need to work out how that variable gets updated when
appropriate. One way is to make this a bindable property with a
custom event type. Now dispatch that event type when the length of
dataProvider changes. Obviously, your getter method for currentView
has to contain the logic you described for deciding which view to use.
Is that what you were looking for?
Cheers,
Lach
On 06/12/2006, at 5:27 AM, Steve Hindle wrote:
Hi All,
I'm trying to create a component to use as an example or 'template'
of how to achieve a record list and detail view in flex. I'm starting
with a simple 'contact' record (model) that has name, address, phone,
email, etc. The list of records is held in _dataProvider, and the
specific record to be displayed in the detail view is held in _model.
My goal is to have a nice clean skeleton of how to handle this sort of
display.
My component is a viewstack with 2 views:
View 0: a datagrid displaying summary info of a list of records
(title, first, last). Double click on an entry should
open it in the
'detail' view. dataProvider is bound to _dataProvider, an
arrayCollection.
View 1: a custom component that displays all my model fields.
It has a 'model' property that is used to set the
record to be displayed.
model is a single static instance of my record type, and
all fields in the
view are bound to it ( eg text='{_model.last_name}' )
The logic for the component is pretty simple:
1. Initial view is determined by _dataProvider.length
2. if _dataProvider.length = 1, default to 'detail' view of that
record
3. if _dataProvider.length > 2, default to 'list' view
4. if _dataProvider.length = 0, add a new empty record and
default to 'detail'
view to allow data entry.
This mostly works - however, I run into 'odd' problems with
dataBinding and Initialization, etc. As my script gets cruftier with
all sorts of special case logic, and
manually poking stuff to get dataBindings updated, I wonder if perhaps
others have a better Design Pattern or template for this ??
I'd appreciate any feedback...