简体   繁体   English

TypeError:在emberjs中未定义newHandlerInfo

[英]TypeError: newHandlerInfo is undefined in emberjs

I came into a very strange bug: yesterday I coded the beginning of an ember.js app, tested it (everything was OK), and pushed it to my github repo . 我遇到了一个非常奇怪的错误:昨天我编写了一个ember.js应用程序的开头,对它进行了测试(一切正常),并将其推送到我的github repo Today I just ran grunt serve (as I did yesterday) but I now get at the beginning the error TypeError: newHandlerInfo is undefined in my browser console. 今天我刚刚运行了grunt serve (正如我昨天所做的那样),但我现在开始出现错误TypeError: newHandlerInfo is undefined在我的浏览器控制台中TypeError: newHandlerInfo is undefined

I don't know what to show so you can check the code on the repo. 我不知道要显示什么,所以你可以查看repo上的代码。 https://github.com/OpenCubes/OpenCubes https://github.com/OpenCubes/OpenCubes

After some debugging, I found that instead of throwing an error, it return an oldHandlerInfo in ember code which is null : 一些调试后,我发现,而不是抛出一个错误,它返回一个oldHandlerInfo在余烬代码为null

// Ideally we should throw this error to provide maximal
// information to the user that not enough context objects
// were provided, but this proves too cumbersome in Ember
// in cases where inner template helpers are evaluated
// before parent helpers un-render, in which cases this
// error somewhat prematurely fires.
//throw new Error("Not enough context objects were provided to complete a transition to " + targetRouteName + ". Specifically, the " + name + " route needs an object that can be serialized into its dynamic URL segments [" + names.join(', ') + "]");
return oldHandlerInfo; //  = UNDEFINED

And the error that should have been thrown is: 应该抛出的错误是:

Not enough context objects were provided to complete a transition to view. 没有提供足够的上下文对象来完成到视图的转换。 Specifically, the mod route needs an object that can be serialized into its dynamic URL segments [mod_model.j_id] 具体来说,mod路由需要一个可以序列化为动态URL段的对象[mod_model.j_id]

Your slugs ( :foo_id ) should match a property name on the model (or you have to do all the serialize, it's easiest to just match). 您的slugs( :foo_id )应与模型上的属性名称匹配(或者您必须执行所有序列化,最简单的匹配)。 It should be unique and can find that resource without knowing anything else (ie a primary key). 它应该是唯一的,并且可以在不知道任何其他内容的情况下找到该资源(即主键)。 Really it makes the most sense to use the id of your record, :id (especially true since you're using Ember Data). 真的,最有意义的是使用你的记录的id :id (尤其是因为你使用的是Ember Data)。

OpencubesDashboard.Router.map( ->
  @resource 'mods', path: '/'
  @resource 'mod', ->
    @resource 'mod', path: '/:id', ->
      @resource 'view', path: '/view'
      @resource 'edit', path: '/edit'

    @route('create')


)

Now your mod route, should use the slug name 现在你的mod路线,应该使用slug名称

OpencubesDashboard.ModRoute = Ember.Route.extend(
  model: (params) ->
    @get('store').find('mod', params.id)
)

Additionally your view and edit resources, are most likely editing/viewing the resource defined on the mod resource (maybe not, I'm just guessing). 此外,您的查看和编辑资源,很可能是编辑/查看mod资源上定义的资源(可能不是,我只是在猜测)。

OpencubesDashboard.ModViewRoute = Ember.Route.extend(
  model: (params) ->
    @modelFor('mod')
  setupController: (controller, model) ->
    controller.set 'model', model
    buffer = model.get('attributes').map (attr)->
      { key: attr.get('key'), value: attr.get('value') }
    controller.set 'buffer', buffer

)

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

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