简体   繁体   中英

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 . 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.

I don't know what to show so you can check the code on the repo. 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 :

// 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]

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). 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).

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

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).

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

)

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