简体   繁体   English

如何使用ember-data和emberjs处理未知ID

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

Based on Rails, Emberjs and ember-data 基于Rails,Emberjs和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? 如果服务器中不存在ID为5的句子,该如何处理?

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. 如果您的服务器发送了404,则对于此类请求,Ember将引发异常,该异常可以通过路由上的errors处理程序进行处理。 From there you can display this in the UI or transitionTo another route that can display the error. 从那里可以在UI中显示此内容,也可以transitionTo到可以显示错误的另一条路线。

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? 为什么这里有两个参数?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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