2013-07-22 2 views
2

내가 서버에서 타다 남은 템플릿을 업로드 할 수 있습니다. 나는처럼 사용할 이러한 요구에 대해 알 :Ember. 라이브 업로드 템플릿

$.ajax({ 
    url: 'url_to_template_text', 
    dataType: 'text', 
    success: function (resp) { 
     App.AboutView = Ember.View.extend({ 
      template: Ember.Handlebars.compile(resp) 
     }); 
    } 
}); 

하지만 페이지에서이보기를 렌더링하는 방법을 이해하지 못할.

<script type="text/x-handlebars" > 
    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="about"> 
    That text cant be show 
</script> 

//////JS 

$.ajax({ 
    url: 'url_to_template_text', 
    dataType: 'text', 
    success: function (resp) { 

     App.AboutView = Ember.View.extend({ 
      templateName: 'about', 
      template: Ember.Handlebars.compile(resp) 
     }); 

    } 
}); 


App.Router.map(function() { 
    this.route("about", { path: "/" }); 
}); 

너무 일을하지 : - App.AboutView.append()는 해당 뷰에 대한 라우팅을 추가 할 경우, 다음 점점 템플릿을 렌더링 할 시간이 없어

근무하지 않습니다. 오래된 템플릿 내용

는 제발 도와주세요, 아마 나는 나쁜 방법을 사용 (내가 의미하는 "텍스트가 표시 될 캔트")를 렌더링되어 있습니까?

답변

3

당신은 model 후크와 함께 템플릿을로드 할 beforeModel 후크를 사용할 수 있습니다. 이 경우이 경로를 사용하여 경로의 기본보기로 해결할 수도 있습니다. 당신은 엠버 규칙을 사용하여이 작업을 수행 할 수 AboutRoute -> AboutView - 등> AboutController,

beforeModel: function() { 
    return $.ajax({ 
    url: '/about.hbs' 
    }) 
    .then(function(response) { 
    Em.TEMPLATES.about = Em.Handlebars.compile(response); 
    }); 
}, 

당신이 세계 Ember.TEMPLATES 객체에 할당해야 템플릿을로드 한 후.

또 다른 방법은, 뷰의 템플릿에 대해 동일한 작업을 수행하는 것입니다. View 클래스를 다시 열고 위와 같이로드 된 템플릿을 추가합니다. 참고로, 핸들 바 템플릿 안의 뷰는 {{view App.MyView}}으로 사용해야합니다.

는 여기 jsbin 예입니다.

+0

덕분에, 자사는 나를 위해 일한 –

관련 문제