简体   繁体   English

渲染木偶CollectionView时如何删除每个childView之间的换行符?

[英]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'

});

demo 演示

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.

相关问题 如何在BackboneJS * marionette * collectionView中打印行线? - how can i print the row line in BackboneJS *marionette* collectionView? 我如何在marionette.js中拥有CollectionView的CollectionView? - how can I have CollectionView of CollectionView in marionette.js? 如何添加 <thead> 带有tagName:&#39;table&#39;的木偶collectionview的部分? - How can I add a <thead> section to a marionette collectionview with tagName: 'table'? Backbone Marionette:我可以为collectionView的emptyView提供选项吗? - Backbone Marionette: can I supply options to a collectionView's emptyView? 如何为Marionette CollectionView生成的选择添加空白选项? - How do I add a blank option to a select generated by a Marionette CollectionView? 如何删除换行符 - How to remove line breaks 如何删除字符串中的换行符,但仅在某些标签之间? - How to remove line breaks from a string, but only between certain tags? 我怎样才能让浏览器允许行内元素之间的换行符(它们之间没有空格)? - How can I get the browser to allow line-breaks between inline elements (with no spaces between them)? 如何使用 Mirth-Javascript 删除 HL7 消息中的换行符? - How can I use a Mirth-Javascript to remove line breaks in HL7 messages? 如何防止 CSS 或 jQuery 中的单词和标点符号之间换行 - How can I prevent line breaks between words and punctuation in CSS or jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM