@Yeevon wrote:
I have two function which is create post and create answer for the post.
For the create post function, the post will render immediate on the web page. But when i add an answer for it, i need to refresh the web page to make the answer render on the web page.
Actually both function are the same, why the post will render after posting it but the answer won’t?
Create Post function:
postQuestion(attrs) const post = this.store.createRecord('post', { title: attrs.title, description: attrs.description, file: attrs.file, }); post.save(); }
Create Answer function:
postAnswer(attrs){ let post = this.store.peekRecord('post',this.model.post.id) let answer = this.store.createRecord('answer', { post: post, answer:attrs.answer, }); answer.save(); },
Create Post Route
model() { return this.store.findAll('post'); }
Create answer route
model(params) { let answer = await this.get('store').query('answer', {filter: { post: params.id }}); return answer; }
Both template render like this:
{{#each model as |post|}} {{post.title}} {{/each}}
Posts: 3
Participants: 3