mercredi 21 janvier 2015

How do I reload data and update a bound element after a user clicks a button?

Why is it that when I click 'Random', the information in the template isn't reset and the data isn't update?


I have data that I want to display after a REST endpoint is successfully reached. My handlebars template looks like this:


app/templates/verses.hbs



<div id="panel">

<h3>{{model.reference_number}}
<h3>{{model.body}}</h3>
<button {{action "getAnotherVerse"}}>Random</button>

</div>
{{outlet}}


So, when the 'Random' button is clicked, the following should be invoked:


app/controllers/verses.js



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

export default Ember.ObjectController.extend({
actions: {
getAnotherVerse: function() {
this.get('model').reload();
// This is where the text should be reset to the new data.
}
}
});




Aucun commentaire:

Enregistrer un commentaire