我在此处修改了list.html 示例https://github.com/tbranyen/backbone.layoutmanager/blob/master/examples/list.html一点:
http://jsfiddle.net/qhoc/nQJz6/
如果您查看 Firebug,您会发现在 ol
和 li
之间有一个额外的 div
。
我知道我可以通过将 li
移出模板并在 Items
View 中使用 tagName: 'li'
来摆脱它。但这意味着我必须在某些地方更改我的代码。此外,为了设计过程的一致性,我更喜欢在模板中保留 li
。
如何在不修改模板的情况下去掉这个div
?
最佳答案
覆盖 partial
函数并像这样执行 jQuery#find
:
Backbone.LayoutManager.configure({
partial: function(root, name, el, append) {
// If no selector is specified, assume the parent should be added to.
var $root = name ? $(root).find(name) : $(root);
// Use the append method if append argument is true.
// Set the element to append to be the first child.
this[append ? "append" : "html"]($root, $(el).children().first());
}
});
此方法可以在全局(上)或本地实例上被覆盖。
您还需要调整 afterRender
以使用新元素:
Backbone.LayoutView.extend({
afterRender: function() {
this.setElement(this.el.firstChild);
this.delegateEvents();
}
});
更多信息在这里:http://tbranyen.github.com/backbone.layoutmanager/#configuration/defaults
关于javascript - 使用 Backbone LayoutManager 的冗余 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062012/