在DIV Backbone.js的关闭使保鲜膜 [英] Backbone.js turning off wrap by div in render
问题描述
我的模型邮和收藏的帖子。并希望使形式与&LT所有职位列表;选择一个id =多多个=多个>
。所以,我不得不做出后览我#multi内渲染眼前这个模板:
I have model Post and collection Posts. And want to make form with list of all post in <select id="multi" multiple="multiple">
. So i have to make a PostView render inside my #multi with just this template:
<option value=""><%= title %></option>
但最后我把它包裹着股利。是否有不包装这个模板&LT任何解决方案; DIV&GT;
推荐答案
如果您不定义报
(或标签名)的视图(类或实例期间)的观点将被置于一个div标签内。 <一href=\"http://documentcloud.github.com/backbone/#View-el\">http://documentcloud.github.com/backbone/#View-el
If you don't define an el
(or tagName) for the view (in the class or during instantiation) the view will be placed inside a div tag. http://documentcloud.github.com/backbone/#View-el
var PostView = Backbone.View.extend({
tagName: 'option'
});
更新
开始v0.9.0,骨干有view.setElement(元素)来完成这件事。
Starting v0.9.0, Backbone has view.setElement(element) to get this done.
var PostView = Backbone.View.extend({
initialize: function() {
var template = _.template('<option value=""><%= title %></option>');
var html = template({title: 'post'});
this.setElement(html);
}
});
这篇关于在DIV Backbone.js的关闭使保鲜膜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!