从加周围的div到一个视图停止骨干? [英] Stop backbone from adding surrounding divs to a view?
问题描述
我使用Handlebars.js作为我Backbone.js的应用程序的模板化的工具。我呈现我的观点函数通常如下所示:
I am using Handlebars.js as a templating tool for my Backbone.js app. My render functions in my views usually look like the following:
var source = $("#round").html();
var template = Handlebars.compile(source);
var context = JSON.parse(JSON.stringify(this.model));
var html = template(context);
$(this.el).html(html);
return this;
以上是通过以下code附加在主应用程序视图(这是code调用上述code):
The above is appended to the main app view through the following code(this is the code that calls the above code):
$('div#round-container', this.el).append(roundView.render().el);
我把手模板处理所有的造型和布局,所以我离开一个视图空白的厄尔尼诺元素。 Backbone.js的自动添加周围围绕着把手模板div标签。我想这是因为厄尔尼诺元素为空。有没有一种方法,以prevent增加周围div标签?谢谢!
My Handlebars template handles all of the styling and layout, so I leave the "el" element of a view blank. Backbone.js automatically adds surrounding div tags around the Handlebars template. I assume this is because the "el" element is blank. Is there a way to prevent the addition of the surrounding div tags? Thanks!
推荐答案
这是怎么回事是 this.el
是动态创建,因为它从来没有明确地由您定。你有两个选择:
What's happening is this.el
is created on the fly because it was never explicitly set by you. You have two options:
-
您应该指定要创建
标签名
,的className
和/或<元素code> ID ,让骨干创建适合你。
You should specify the element you want to create with
tagName
,className
and/orid
and let backbone create that for you.
在渲染
应 this.el
设置为你的车把模板的内容。所以,你将有 this.el = $(模板(上下文))
。
In render
you should set this.el
to the contents of your handlebars template. So you would have this.el = $(template(context))
.
该文档具有扩展的解释 - <一个href=\"http://documentcloud.github.com/backbone/#View-el\">http://documentcloud.github.com/backbone/#View-el
The docs have an expanded explanation - http://documentcloud.github.com/backbone/#View-el
这篇关于从加周围的div到一个视图停止骨干?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!