PDA

View Full Version : Understanding models and stores



BillHubbard
26 Apr 2013, 12:18 PM
Sorry if this is a basic question, but I'm having trouble understanding models and stores. I have a service that accepts a number of parameters, and for each parameter it returns a list of items in its own section of the JSON response. Conceptually:


{"section1": [
{ "name": "Item1", "description": "Item1 description"},
{ "name": "Item2", "description": "Item2 description"},
{ "name": "Item3", "description": "Item3 description"}
}],
"section2": [
{ "name": "Item1", "description": "Item1 description"},
{ "name": "Item2", "description": "Item2 description"},
{ "name": "Item3", "description": "Item3 description"}
]}


How do I define the model for this? FYI, I'm stuck in a 4.0.5 environment...

BillHubbard
26 Apr 2013, 4:17 PM
Additionally, I have a case where I have a JSON response that returns three properties, name, description, and attributes, and attributes is a list of records for which I want to create model objects. In any one or more of those records in the attributes list, a property could exist to carry the same exact (nested) structure, with name, description and attributes list. There is no restriction on depth. Basically, a tree structure.

How is it possible to construct a model/store in ExtJS (4.0.5) to deal with this?

slemmon
29 Apr 2013, 3:45 PM
With the model with multiple roots (section1, section2) will each node be used in a different store of records? If not, can you nest the different roots under another parent node?



sections: {
section1: [],
section2: []
}


For infinite models-owning-models the only thing that comes to mind is the TreeStore. The TreeStore is used by the treepanel, but could be used stand-alone, too, if needed.