如何加载骨干pcomplied模板$ P $? [英] how to load precomplied template in backbone?
问题描述
请你告诉我如何加载precomplied模板。我GOOGLE了它,并找到解决的办法。现在我不知道如何使用这个function.could请你告诉我怎样使用这个功能吗?
code:
http://goo.gl/ALfkzf
Backbone.Marionette.TemplateCache.prototype.loadTemplate =功能(templateId,回调){
变种tmpId = templateId.replace(#,),
URL =/应用/模板/+ tmpId +。html的; $获得(URL,功能(templateHtml){
compiledTemplate = Handlebars.compile($(templateHtml)的.html())
callback.call(这一点,compiledTemplate);
});
}; Backbone.Marionette.Renderer.renderTemplate =函数(templateId,数据){
变种呈示= $ .Deferred();
Backbone.Marionette.TemplateCache.get(templateId,功能(模板){
VAR HTML模板=(数据);
renderer.resolve(HTML);
});
返回renderer.promise();
};
我试图加载HTML文件是目录内的?模板/ test.html的
VAR ToolItemView = Backbone.Marionette.ItemView.extend({
模板:模板/ test.html的,});
在code,你要使用,取代默认的HTML机制木偶。
- '模板/ test.html的将转化为/app/templates/template/test.html.html,我的猜测是不是你想要的(要么改变URL生成,或模板指针)
- 您骨干code,不承担,认为的test.html是pcompiled上违背编译$ P $是发生在客户端上,下面的GET回应,这是你想要的吗?
- 对于骨干网覆盖使用,你应该尽量使你的ToolItemView之前被调用,因此基本上可以称之为code ToolItemView之前的任何地方进行渲染。
could you please tell me how to load precomplied templates .I googled it and find a solution .Now I don't know how to use this function.could you please tell me how to use this function ? code: http://goo.gl/ALfkzf
Backbone.Marionette.TemplateCache.prototype.loadTemplate = function (templateId, callback) {
var tmpId = templateId.replace("#", ""),
url = "/app/templates/" + tmpId + ".html";
$.get(url, function (templateHtml) {
compiledTemplate = Handlebars.compile($(templateHtml).html())
callback.call(this, compiledTemplate);
});
};
Backbone.Marionette.Renderer.renderTemplate = function (templateId, data) {
var renderer = $.Deferred();
Backbone.Marionette.TemplateCache.get(templateId, function(template){
var html = template(data);
renderer.resolve(html);
});
return renderer.promise();
};
I am trying to load html file which is inside the directory ? template/test.html
var ToolItemView = Backbone.Marionette.ItemView.extend({
template: 'template/test.html',
});
The code that you are trying to use, replaces default HTML mechanism in Marionette.
- 'template/test.html' will be translated to "/app/templates/template/test.html.html", which I guess is not what you want (Either change url generation, or template pointer)
- Your Backbone code, does not assume, that "test.html" was precompiled on contrary compilation is happening on the client, following GET response, is this what you want?
- Regarding Backbone override use, it should be called before you try to render your ToolItemView, so basically you can call this code anywhere before ToolItemView render.
这篇关于如何加载骨干pcomplied模板$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!