Detect route/view transition in Ember.js application -


the router of application looks (it's coffeescript):

app.router.map () ->   @resource 'conversations', { path: '/' } ->     @resource 'conversation', { path: ':conversation_id' }     @route 'new' 

so, in app, have paths /new, /1, /2, etc.

i detect transition /1 /2 make initializations in view (basically, put focus on textarea field). unfortunately, /1 , /2 use same route, seems impossible detect transition.

i tried using didinsertelement in view (as described here) or observing currentpath in controller (as described here). works fine if go /new /1 (different routes) not if go /1 /2.

i found this gist suggesting use statemanager seems outdated (and i'm not sure it's need).

what suggest me do?

edit

it seems setupcontroller called every time decided overload this:

app.conversationroute = ember.route.extend {    setupcontroller: (controller, model) ->     controller.set 'model', model     # here?  } 

and want init method in view called:

app.conversationview = ember.view.extend {    init: ->     @$('form textarea').focus()  } 

but still can't figure out how make these 2 things work (it's problem because read controller not supposed know view).

thank help!

use didinsertelement view hook , observer.

app.conversationview = ember.view.extend    didinsertelement: ->     @focusontextarea()    modelchanged: (->     @focusontextarea()   ).observes('controller.model')    focusontextarea: ->     @$('form textarea').focus() 

in case of going /1 /2, route , view not changing. ember least amount of work possible. there's no need re-render view, doesn't. tripped me too, , think it's big gotcha.

also, if override init in view, make sure call @_super().

note: model hook called when landing on page deserialize url, not when transitioning page , changing model instance.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -