1
엠버 라우터를 사용하여 엠버 앱에 검색 필드를 구현했습니다. 내 라우터의 관련 부분은 다음과 같습니다.현재 경로의 컨텍스트 가져 오기
question: Em.Route.extend({
route: '/?query=:query'
connectOutlets: function(router, context) {
query = context['query'],
articles = App.get('defaultStore').findQuery(App.Article, {"query": query})
router.get('helpController').connectOutlet('articlesSearch', 'articlesSearch', articles)
}
})
내 검색 필드의 값을 현재 경로의 컨텍스트에 바인딩하고 싶습니다. 나는이 같은 내 컨트롤러에서 구현되는 stateMetaFor
방법을 사용하여 내 컨트롤러에서이 작업을 수행 할 수있는 방법을 발견 : 1)는 문서화되지 않은 findStateByPath
방법을 사용하고 있기 때문에이 방법에 만족하지 않다
query: function() {
router = App.get('router')
state = router.findStateByPath(router.get('currentState'), 'help.question')
if (router.get('currentState') == state) {
stateMeta = router.stateMetaFor(state)
return stateMeta['context']['query]
}
return ''
}.property('App.router.currentState').cacheable()
2) 이는 stateMeta 객체의 내부 지식을 필요로하기 때문입니다. 이 작업을 수행하는 더 좋은 방법이 있습니까? 없다면, 있어야할까요?