In my ember app, I am displaying a list of books
BOOKS
Book Author
Gorgeous Metal Fish Cookbook Jefferey Gibson
I am trying to display author's information ( in a modal window) upon click on the author's name in my books template, I have an action 'showAuthor' , defined in the the books route, but I get undefined data...
<span ></span>
**TEMPLATES**
<!-- app/templates/books.hbs -->
<h1>Books</h1>
<table class="table table-bordered table-striped">
<thead>
. . .
</thead>
<tbody>
<tr>
<td>
. . .
</td>
<td>
<span ></span>
</td>
</tr>
</tbody>
</table>
============
**MODELS**
// app/models/book.js
export default Model.extend({
. . .
author: belongsTo('author', {inverse: 'books', async: true}),
. . .
});
// app/models/author.js
export default Model.extend({
. . .
books: hasMany('book', {inverse: 'author', async: true}),
. . .
});
=========
**ROUTES**
app/routes/books.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('book');
},
actions: {
.. .
showBookAuthor(book){
alert('SHOW BOOK AUTHOR : ' + book.author.name);
},
. . .
}
});
app/routes/authors.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('author');
},
actions: {
.. .
}
});
Aucun commentaire:
Enregistrer un commentaire