수동으로 사전 컴파일하여 저장 한 핸들 막대 템플릿이 있습니다 (예 : testTemplate.handlebars).RequireJS가 포함 된 미리 컴파일 된 핸들 막대
define(['text!../templates/testTemplate.handlebars'
],function(testTemplate){
var myView = Backbone.View.extend(
initialize: function(options){
this.template = Handlebars.template(testTemplate);
},
render: function(data){
$(this.el).html(this.template(data));
}
);
});
그래서 testTemplate.handlebars이 Handlebars.template에 전달 된 문자열의 형태로 자바 스크립트 코드를 반환 JS 함수를 반환 -
지금, + 백본 코드 내 requireJS에서 나는 아래의 기능이 . 함수가 실행 렌더링의 $(this.el).html(this.template(data));
, 그것은라는 오류 메시지를 제공합니다 - - 라인이
function (n,r){return r=r||{},e.call(t,Handlebars,n,r.helpers,r.partials,r.data)}
하지만 - 나는 콘솔에 값을 인쇄했을 때 나는 this.template가 표시 변수에 얻을 catch되지 않은 형식 오류를 : 객체에는 메서드 호출이 없습니다. (비록 내가 e.call 기능을 볼 수있다)
내가 여기서 뭔가 잘못하고 있니?
또한 템플릿 런타임을 컴파일하려고하면 렌더링 기능이 작동합니다. 런타임 컴파일 Handlebars.compile (testTemplate) 아래 함수가 반환하는 동안 -
당신이 그것을 미리 컴파일 한 경우function (e,t){return n||(n=r()),n.call(this,e,t)}