简体   繁体   中英

how to deal with the unknown id with ember-data and emberjs

Based on Rails, Emberjs and ember-data

Route

App.Router.map ->
  @resource "sentences", ->
    @resource "sentence",
      path: ":sentence_id", ->

Model

App.Sentence = DS.Model.extend(
  subject: DS.attr("string")
)

visit the url

http://localhost:3000/#/sentences/5

if the sentence with the id 5 does not exist in the server, how to deal with that?

If your server sends a 404, for such a request, Ember will raise an exception which can be handled via an errors handler on the route. From there you can display this in the UI or transitionTo another route that can display the error.

App.PostRoute = Ember.Route.extend({
  events: {
    error: function(reason, transition) {
      // display error or transitionTo here
    }
  }
});

how to use the two params 'reason', 'transition'
Is it possible to show one example

why does it have two params here?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM