Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| richclient:emberjs:data:crud [2018/02/04 20:04] – [Flags, dirty attributes et annulation] jcheron | richclient:emberjs:data:crud [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 140: | Ligne 140: | ||
| ===== Erreurs de validation ===== | ===== Erreurs de validation ===== | ||
| + | Côté router, il est possible d' | ||
| + | <sxh javascript> | ||
| + | import Route from ' | ||
| + | |||
| + | export default Route.extend({ | ||
| + | model(params) { | ||
| + | return this.get(' | ||
| + | }, | ||
| + | |||
| + | actions: { | ||
| + | error(error, | ||
| + | if (error.status === ' | ||
| + | this.replaceWith(' | ||
| + | } else { | ||
| + | // Let the route above this handle the error. | ||
| + | return true; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | |||
| + | Si le serveur retourne des erreurs de validation au moment du save, la propriété **errors** du model permet de les afficher : | ||
| + | |||
| + | <sxh html> | ||
| + | {{#each post.errors.title as |error|}} | ||
| + | <div class=" | ||
| + | {{/each}} | ||
| + | {{#each post.errors.body as |error|}} | ||
| + | <div class=" | ||
| + | {{/each}} | ||
| + | </ | ||
| + | |||
| + | |||
| + | Il existe également un **loading event** permettant d' | ||
| + | |||
| + | <sxh javascript> | ||
| + | import Route from ' | ||
| + | |||
| + | export default Route.extend({ | ||
| + | ... | ||
| + | actions: { | ||
| + | loading(transition) { | ||
| + | let start = new Date(); | ||
| + | transition.promise.finally(() => { | ||
| + | this.get(' | ||
| + | }); | ||
| + | |||
| + | return true; | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| ===== Promises ===== | ===== Promises ===== | ||