Reputation: 5119
I'm working on a proof of concept app and I have a question about data storage.
My app has a client model
PM.Client = Ember.Object.extend({
id: null,
client: null,
projects: {}
});
and a projects model
PM.Project = Ember.Object.extend({
id: null,
title: null,
totalHours: null,
cost: function(){
return this.get('totalHours') * PM.get('rate');
}.property('totalHours')
});
Each client can have multiple projects, but each project can only have one client. Currently I have a dummy JSON file with the following data
[
{
"id": "1",
"client": "Fastbook",
"projects": [
{
"id": "1",
"title": "Website redesign",
"totalHours": "45",
"cost": "4500"
},
{
"id": "2",
"title": "Tidy up admin section",
"totalHours": "10",
"cost": "1000"
}
]
},
{
"id": "2",
"client": "Epicenter",
"projects": [
{
"id": "1",
"title": "Chaching",
"totalHours": "25",
"cost": "2500"
}
]
}
]
What's the best way to store this data within Ember? Should I have an arrayController for clients and another for projects?
Ember Data might be okay but I don't plan on having REST set up for this. Can Ember Data use localStorage?
Upvotes: 4
Views: 762
Reputation: 1531
I have nested data in an ember feed reader I'm working on.
I use 2 array controllers. I have a set of feeds and each feed contains entries.
For my use, where selecting a feed should show you the entries it contains, I have a feedController, a selectedFeedController, an entryController and a selectedEntryController.
This allows me fairly fine grained control. Hope that pushes you to get started, and maybe figure out if this isn't the right model for you.
Upvotes: 1
Reputation: 461
I agree with @David and @ebryn. It completely depends on the use case. Do you always use the user and project data together for example? Then there is no need for separate array controllers, especially since the data is already nested.
But if you want to go for clear separation of concerns then you should indeed consider two separate controllers.
Also to read data from localstorage only you will have to define your own adapter, there is no built in method. The steps to follow to build your own adapter is detailed in the ember data github page towards the end of the readme.
Upvotes: 0
Reputation: 26
I assume there will be, in the final wash, a client detail view with a project list attached, and a project list view with all active projects across the clients.
Let the use cases dictate the object model, not the object model dictate the use cases. If you need the scenario above, you will probably be jumping through hoops if you only have a client ArrayController; it will be more natural to have both client and project ArrayControllers in this case.
Upvotes: 0
Reputation: 4407
It's somewhat hard to say without more details as to what the application will be doing.
I would use an ArrayController
for clients. I don't see the need for there to be one for projects, since that data is nested inside the client objects. If you have a display where a project gets selected, you might want to have a controller for the currently selected project.
If you could further describe what you intend to do with the project data, I could better advise.
Upvotes: 1