I'm having problem to understand how to work with ember-data models in my views and controllers. I'm writing app using emberjs 1.2.0 + ember-data 1.0.0-beta.2. I've writing my own custom RESTAdapter and Serializer for our (crazy) API. Everything seems to work fine -> I can work with model's data in my templates and so on.
I'll try to explain basic functionality of app. For example I have UserModel with collection of Users and than I have a template for list of users and user detail where you can edit profiles and so. Everything is pretty clean there. Then I have another model call Location with last location associated to user. This model I'm using in my template with google maps where I need to use this model (in my mapView) for creating annotations in map. Another example is reportModel with day stats of user's activity. This model I need to to build dc.js charts with those stats. Without ember-data I basically set ajaxRequest in Route's model hook and than I can get data in my controller or view. I'm trying turn this route to using ember-data as rest of app but I don't really know how to get model's data in View or controller when get('model') returns DS.Model's class.
Little bit of code:
App.DashboardRoute = App.AuthenticatedRoute.extend({
model: function() {
return this.store.find('daystat');
},
setupController: function(controller, model) {
controller.set('content', model);
}
});
App.DashboardView = Ember.View.extend({
didInsertElement: function() {
// load model from controller
var model = this.get('controller.content');
console.log(model);
}
});
console log on Dashboard route:
Class
__ember1391503821834: "ember608"
__ember1391503821834_meta: Meta
_oldWillDestroy: function superWrapper() {
_super: undefined
arrangedContent: (...)
content: (...)
get content: function () {
set content: function (value) {
isLoaded: true
isUpdating: false
store: Class
toString: function () { return ret; }
type: App.Daystat
willDestroy: function superWrapper() {
__proto__: Object
Rest Serializer log before pushing api response to store with data I exactly want to work with in Dashboard View:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, nextObject: function, firstObject: undefined, lastObject: undefined, contains: function, getEach: function…]
Single object (date) containts someting like:
date: "2014-01-18"
id: 4
orders_count: 0
orders_sum: 0
sales_count: 0
sales_sum: 0
visits_count: 0
__proto__: Object
My question is: how can I work with Ember-Data Models in my views or controllers like I do in my handlebars templates?