I am trying to sort my posts so that the most recent appears on my blog central page. I am able to manipulate by author and title, but I am really trying to get the most recent published date to appear at the top of the page. Is there something I need to do with the sortproperties on the controller? I've tried messing with the "limitToFirst" and "limitToLast" as well. I also tried "publishedDate" instead of published, but published appears in the "Ember Inspector", so I think published is what I want. Here is my code below:
controllers/post.js
import Ember from 'ember';
export default Ember.Controller.extend({
sortProperties: ['published'],
sortAscending: false, // sorts post by timestamp
actions: {
publishPost: function() {
var newPost = this.store.createRecord('post', {
title: this.get('title'),
post: this.get('post'),
author: this.get('author'),
published: new Date().getTime()
});
newPost.save();
}
}
});
models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
post: DS.attr('string'),
published: DS.attr('number'),
publishedDate: Ember.computed('published', function() {
return moment(this.get('published')).format('MMMM Do, YYYY');
})
});
route/post.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.query('post', {
orderBy: 'publishedDate',
limitToFirst: 10
});
}
});
template/blog.js
<h2>Below are your Latest Blog Posts</h2>
<div class="col-sm-8">
<div id=blogPost>
<div id='published'><p>Published: </p></div>
<div id='title'><p>Title: </p></div>
<div id='author'><p>Author: </p></div>
<div id='body'><p>Post: </p></div>
</div>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire