ember.js - How to handle time based relationships in ember data? -
Assuming I have two models users
and posts
are one Users
can have multiple posts
and each corresponds to post
a user
. On special pages, I would like to display posted
on a date, usually only today's post. How do I design relationships?
I can create a method in the controllers such as
App.ProfileController = Ember.ObjectController.extend getPostsForToday: (- & gt; @ store.all ( 'Post'). Filter property ('date', '2014-10-17')
But I think I should put this argument in the model
App.User = DS.Model.extend todayPosts: (-> DS.hasMany ("Post"). Filter Receipt ('Date', '2014-10-17') // Something like this
In this way, I can not dynamically change the date, can I do it? What is the best strategy to handle?
I think one to do this < Code> ArrayController , it has to be sorted in it, and filtering results is on your way.
ArrayController:
App TodaysPostsController = Ember.ArrayController.extend ({sortBy: 'date'});
Controller:
APP file controller = Amber Object Controller Extension ({Required: [Today's Posts], Today's Posts: Amber dot cop Elias ('Controllers. Dedes Post'),});
Root:
App.ProfileRoute = Ember.Route.extend ({setupController: function (controller, model) {// default functioning _ Super (controller, model); this.store.findAll ('post'); var $ this = this; var today = '2014-10-17'; // whenever this change occurs in post models, it Will be updated .filter ('post', {'date': today}, function (post) {return post. Get ('date');}). Then (function (today's post) {$ this.controllerFor ( 'TodaysPosts'). Set ('model', today's post);});}});
Information on array controller
Information on store filtering
Comments
Post a Comment