2014-09-04 2 views
0

어떤 방법 으로든 코드의 일부에서 라우터 :id 값을 얻을 수 있습니다.에버에서 링크 도우미로 현재/선택된 ID를 얻는 방법

(예컨대 때 제어기로 전류 값 저장 소성으로 링크) I 라우터

this.resource('consultations', function() { 
     this.resource('consultation',{path: '/:id'}); 
    }); 

링크 - 중첩 행에에게

{{#link-to 'consultation' item}}-{{/link-to}} 

루트 협의

model: function() {return this.store.find('consultation')} 

경로 상담

상담 afterModel에서
model: function (consultation) { 
     alert(consultation.id); //alert was shown only once, I can't remember current Id 
     return this.store.find('consultation',consultation.id); 
    }, 

나는 소켓 연결을하고 난

afterModel: function() { 
     socket.on('message', function (message) { 
     //here I need to know current consultation ID 
     }); 

내부 선택한 ID}

답변

0

afterModel 가장 먼저 해결 된 모델이되는 몇 가지 인수를 받아 필요합니다.

afterModel: function(resolvedModel) { 
    socket.on('message', function (message) { 
    var id = resolvedModel.get('id'); 
    }); 
} 

자세한 내용은 found in the Ember docs을 할 수있다 : 이것은 당신이 메소드 본문에서의 ID를 잡아 수 있습니다.