[英]How can I remove line breaks between each childView when rendering a Marionette CollectionView?
In MarionetteJS, when creating a CollectionView, all the children are automatically separated by line breaks when rendered. 在MarionetteJS中,创建CollectionView时,所有子项在呈现时都会自动由换行符分隔。 I would like the children in a particular CollectionView that I have to be rendered in order without a line break added (effectively replacing the line break with a space).
我希望必须在不添加换行符的情况下按顺序渲染特定CollectionView中的子级(有效地将换行符替换为空格)。
I've looked through the source code, and am sure that I need to alter one of the functions that is called from the render method of the CollectionView. 我仔细阅读了源代码,并确定需要更改从CollectionView的render方法调用的函数之一。 However, I can't for the life of me figure out what it is that needs to be altered.
但是,我无法为自己的一生弄清楚需要更改的内容。
To find the function in question, find "Render children views" on this annotated source code page: http://marionettejs.com/annotated-src/backbone.marionette.html If anybody can help me figure out what needs to be altered, I would really appreciate that! 要查找有问题的函数,请在此带注释的源代码页面上找到“渲染子视图”: http : //marionettejs.com/annotated-src/backbone.marionette.html如果有人可以帮助我找出需要更改的内容,我真的很感激!
Every view needs to either be handed a DOM element to use as a root or create one itself. 每个视图都需要传递一个DOM元素以用作根,也可以自己创建一个。 You can control what tag an ItemView uses as root with the
tagName
property. 您可以使用
tagName
属性控制ItemView用作根的标记。 The default is <div>
which is a block element and that's why you get linebreaks. 默认值为
<div>
,它是一个块元素,这就是为什么要换行的原因。
You have a couple of options here, and none of them is editing the Marionette source. 您在此处有几个选项,但都没有编辑Marionette源。
You can either have you view use an inline element (like a <span>
) as a root, which is the option I would prefer. 您可以查看使用内联元素(例如
<span>
)作为根,这是我希望使用的选项。
var ItemView = Backbone.Marionette.ItemView.extend({
template: '#template',
tagName: 'span'
});
Or you could use CSS to set the root element of your ItemView to display: inline-block
. 或者,您可以使用CSS将ItemView的根元素设置为
display: inline-block
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.