vendredi 20 novembre 2015

EmberJs - Get specific item in model

New to ember js, so bare with me! I've created a new ember project and connected it to firebase. I'm retrieving all posts fine, and displaying all posts fine, but I want to display just a single post.

I'm using ember v1.13.11

Model - app/models/post.js :

import Ember from 'ember';
import DS from 'ember-data';

let {
  Model,
  attr
} = DS;

export default Model.extend({
  title: attr('string'),
  createdDate: attr('date'),
  text: attr('string'),
  imgURL: attr('string')
});

Route - app/routes/index.js:

import Ember from 'ember';

export default Ember.Route.extend({
        model(){
                return this.store.findAll('post');
        }
});

template - app/templates/index.hbs:

{{#each model as |post|}}
<div class="panel panel-default">
        <div class="panel-heading">
                {{post.title}}
        </div>
        <div class="panel-body">
        <p>{{post.text}}</p>
        <br />
        <img src="{{post.imgURL}}">
        </div>
</div>
{{/each}}

This all works fine. However I was to display a specific post. I thought this would work, but I was wrong.

<div class="panel panel-default">
        <div class="panel-heading">
                {{post.1.title}}
        </div>
        <div class="panel-body">
        <p>{{post.1.text}}</p>
        <br />
        <img src="{{post.1.imgURL}}">
        </div>
    </div>

// OR

<div class="panel panel-default">
        <div class="panel-heading">
                {{post.[1].title}}
        </div>
        <div class="panel-body">
        <p>{{post.[1].text}}</p>
        <br />
        <img src="{{post.[1].imgURL}}">
        </div>
    </div>

Any ideas?




Aucun commentaire:

Enregistrer un commentaire