How to use associated Model as datasource for DataView
Posted
by
Chris Gilbert
on Stack Overflow
See other posts from Stack Overflow
or by Chris Gilbert
Published on 2012-11-29T11:43:30Z
Indexed on
2012/12/02
23:05 UTC
Read the original article
Hit count: 264
I have a Model structure as shown below and I want to know how to use the Bookings array as the datasource of my DataView.
Model Structure:
Client
ClientId
Name
Bookings (HasManyAssociation)
Contacts (HasManyAssociation)
AjaxProxy
JsonReader (ImplicitIncludes is set to true so child models are created with one call)
Booking
BookingNodeId
BookingDetails
Contact
ContactNodeId
ContactDetails
The above gives me a data structure as follows:
Client
Bookings[
Booking
Booking
]
Contacts[
Contact
Contact
]
What I want to be able to do is either, create a Store from my Bookings array and then use that store as the datasource for my DataView OR directly use the Bookings array as the datasource (I don't really care how I do it to be honest).
If I setup the AjaxProxy on my Booking model it works fine but then obviously I cannot automatically create my Client and Contacts when I load my JSON.
It seems to me to make sense that the Client model, being the top level model hierarchically, is the one to load the data.
EDIT:
I figured it out as follows (with special thanks to handet87 below for his dataview.setStore() pointer).
The key in this case is to know that creating the relationship actually sets up another store called, in this case BookingsStore and ContactsStore. All I needed to do was dataview.setStore("BookingsStore")
© Stack Overflow or respective owner