I've started working on Discourse plugin and learning about Ember. I have 'keynote' model, which has 3 attributes: id, key, link. My problem is that when I create new keynote - it displays on keynotes page but if I reload page - results disappear. I'm sure that the problem in my fetch method. Here is my views page:
<button onclick="createKeynote">Create</button>
<form >
<input type="text" id= key_area>
<input type="text" id= link_area>
<button type='submit' class='btn btn-primary'>
</button>
</form>
<ul>
<li>
--> ==>
</li>
</ul>
Here is the page for my keynotes controller:
export default Ember.Controller.extend({
init() {
this._super();
this.set('keynotes', []);
this.fetchKeynotes();
},
fetchKeynotes() {
this.store.findAll('keynote')
.then(result => {
for (const keynote of [result.link] && [result.key]) {
this.keynotes.pushObject(keynote);
}
})
.catch(console.error);
},
actions: {
createKeynote(key, link)
{
key = document.getElementById("key_area").value
link = document.getElementById("link_area").value
const keynote_full = {};
keynote_full[key] = link
const keynoteRecord = this.store.createRecord('keynote', {
id: Date.now(),
key: key,
link: link
});
console.log(keynoteRecord)
keynoteRecord.save()
.then(result => {
this.keynotes.pushObject(result.target);
})
.catch(console.error);
}
}
});
Pay attention to 'fetchKeynotes' method - if I would try to console.log(findAll('keynote')) - it would give me out all attributes and also arrangedContent in which one contains all of the keynotes with all attributes (id, key, link), so as I said - I'm sure, that something is wrong with 'fetchKeynotes' method but I am not sure why.
Aucun commentaire:
Enregistrer un commentaire