有没有更好的方法在文本块中添加换行符而不是在每个项目之后添加
?(Is there a better way to add line-breaks in a block of text than just putting
after every item?)

我有一个很大的项目列表,其格式如下:

list item <br>
list item <br>
list item <br>
list item <br>
list item <br>
list item <br>

等等

目前,我已经通过在每个项目之后添加br来让他们工作,但它有点混乱。 是否有一些我可以使用的CSS或HTML会在每个项目后自动断行? 它们目前都在p标签内。


I have a big list of items that are formatted like so:

list item <br>
list item <br>
list item <br>
list item <br>
list item <br>
list item <br>

etc.

Currently, I've got them to work by putting a br after every item, but it's kinda messy. Is there some CSS or HTML that I can use that will automatically break the line after each item? They are all currently inside a p tag.


原文:https://stackoverflow.com/questions/35588559
2024-04-24 14:04

满意答案

在您的示例中, mapforEach之间的本质区别在于forEach对原始数组元素进行操作,而map显式返回一个新的数组。

使用forEach您将对原始数组中的每个元素进行一些操作(可选择更改)。 forEach方法运行您为每个元素提供的函数,但不返回任何内容( undefined )。 另一方面, map遍历数组,对每个元素应用一个函数,并将结果作为新的数组发出

forEach的“副作用”是原来的数组正在改变。 使用map “无副作用”意味着,在惯用语中,原始数组元素改变; 新数组是原始数组中每个元素的一对一映射 - 映射变换是您提供的函数。

没有数据库涉及的事实并不意味着您不必对数据结构进行操作,毕竟这是数据结构中任何语言的编程之一。 对于你最后一个问题,你的数组不仅可以包含数字,而且可以包含对象,字符串,函数等。


The essential difference between map and forEach in your example is that forEach operates on the original array elements, whereas map explicitly returns a new array as a result.

With forEach you are taking some action with -- and optionally changing -- each element in the original array. The forEach method runs the function you provide for each element, but returns nothing (undefined). On the other hand, map walks through the array, applies a function to each element, and emits the result as a new array.

The "side effect" with forEach is that the original array is being changed. "No side effect" with map means that, in idiomatic usage, the original array elements are not changed; the new array is a one-to-one mapping of each element in the original array -- the mapping transform being your provided function.

The fact that there's no database involved does not mean that you won't have to operate on data structures, which, after all, is one of the essences of programming in any language. As for your last question, your array can contain not only numbers, but objects, strings, functions, etc.

相关问答

更多

javascript - 在Map.prototype.forEach()中获取索引(javascript - get index in Map.prototype.forEach())

Map.prototype.forEach用两个参数进行回调:值和键。 不,它用三个参数调用 ,就像Array#forEach 。 第三个是地图。 是否有可能获得每个条目的索引,类似于Array.prototype.forEach(functcion(value, index) => {}) (相当肯定, functcion部分并不意味着在那里。) 这是key所在。 没有单独的“索引”。 Map的迭代次序是为各种迭代操作定义的,但是没有直接的迭代构造给你索引 (而不是键 )的顺序。 订单是原始的关...

[.forEach.call()在JavaScript中做什么?(What does [].forEach.call() do in JavaScript?)

[]是一个数组。 这个数组根本不用。 它被放在页面上,因为使用数组可以访问阵列原型,如.forEach 。 这比键入Array.prototype.forEach.call(...);要快Array.prototype.forEach.call(...); 接下来, forEach是一个将函数作为输入的函数... [1,2,3].forEach(function (num) { console.log(num); }); ...对于this ( this是数组式的)中的每个元素,因为它有一个le...

javascript forEach方法有什么用途(该地图无法做什么)?(what use does the javascript forEach method have (that map can't do)?)

在您的示例中, map和forEach之间的本质区别在于forEach对原始数组元素进行操作,而map显式返回一个新的数组。 使用forEach您将对原始数组中的每个元素进行一些操作(可选择更改)。 forEach方法运行您为每个元素提供的函数,但不返回任何内容( undefined )。 另一方面, map遍历数组,对每个元素应用一个函数,并将结果作为新的数组发出 。 forEach的“副作用”是原来的数组正在改变。 使用map “无副作用”意味着,在惯用语中,原始数组元素不改变; 新数组是原始...

如何停止Javascript forEach?(how to stop Javascript forEach? [duplicate])

你不能从一个forEach打破。 我可以想到三种方式来伪造它。 丑陋的方式 :将第二个参数传递给forEach 用作上下文 ,并在其中存储一个布尔值,然后使用if 。 这看起来很可怕 2.有争议的方式 :在try-catch块中围绕整个事物,当你想要破解时抛出异常。 这看起来很糟糕, 可能会影响性能 ,但可以封装。 有趣的方式 :使用every() 。 ['a', 'b', 'c'].every(function(element, index) { // Do your thing, then...

Javascript递归,foreach循环不会退出?(Javascript recursion, foreach loop won't exit?)

如果找到,您可以使用Array#some的短路并返回存储的节点。 some()为数组中存在的每个元素执行一次callback函数,直到找到callback函数返回一个真值(在转换为布尔值时变为true值)为止。 function getNodeById(currentNode, id) { var node; if (currentNode.id === id) { return currentNode; } currentNode.children...

使用forEach方法更改项目的属性(javascript)(Change Properties of Items using a forEach Method (javascript))

删除引号如: var myArray = [div1,div2,div3] Remove the quotes like: var myArray = [div1,div2,div3]

JavaScript - ForEach(JavaScript - ForEach)

您不需要使用this , self或任何其他上下文来调用helpPerson。 直接调用它: var people = [ { id:1, firstName: 'Joe', lastName: 'Smith' }, { id:2, firstName: 'Bill', lastName: 'Smith' } ]; function doSomething() { people.forEach(function(person) { helpPerson(person); ...

想要通过使用Javascripts map,reduce,foreach,filter方法来实现功能(Want to achieve functionality by using Javascripts map,reduce,foreach,filter methods)

这是使用filter和forEach方法的解决方案,使用callback函数。 见这里的参考: 过滤方法 var students = [ { firstname: "stud1", lastname: "stud2", marks: "60" }, { firstname: "stud3", lastname: "stud4", marks: "30" }, { firstname: "stud5", lastname: "stud6", marks: "70" }...

For循环,map和forEach Javascript(For-loop, map and forEach Javascript)

您没有从map函数返回任何内容,因此隐式返回值undefined ,因此您的数组包含13个undefined值。 suits.forEach需要return suits.map 。 这将给出一个包含13个元素的数组,其中每个元素是一个包含四个元素的数组,其中内部数组的每个元素都是一个两个元素[suit, value]数组。 然后,您可以将顶级数组reduce为您所追求的52个元素数组: var newDeck = values.map(function(xValue) { return sui...

javascript forEach范围(javascript forEach scope)

您链接到州的文档 如果向forEach()提供thisArg参数,则在调用时它将被传递给回调,以用作其此值。 否则,将传递undefined的值以用作其此值。 最终通过回调可观察到的this值根据用于确定函数所见的通常规则来确定。 所以,要得到你想要的 tempGameState.forEach(function(...){ ... }, this)) ^^^^^^ The documentation you linked to states If a thisArg parameter...

相关文章

更多

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Create a Bootable MicroSD Card

http://gumstix.org/create-a-bootable-microsd-card.h ...

Securing Solr on Tomcat access using a user account

Open [Tomcat install dir]\tomcat-users.xmlfor editi ...

按钮样式

网页上有很多功能是通过链接方式传递参数,这种功能链接普通样式就是一个超链接退出,如果将超链接的样式变成 ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

A Great List of Windows Tools

Windowsis an extremely effective and a an efficient ...

Become a Master Designer: Rule Three: Contrast, Contrast, Contrast

Part Three of Seven Easy Principles to Becoming a M ...

Stack Overflow Architecture Update - Now At 95 Million Page Views A Month

A lot has happened since my first article on theSta ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

Hibernate 异常之:associate a collection with two ...

Hibernate exception - Illegal attempt to associate ...

最新问答

更多

sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)

否(它不会使它们无法访问),是(您可以在没有停机的情况下运行它)。 sp_updatestats可以在没有停机的情况下针对实时数据库运行。 No (it doesn't make them inaccessible), and Yes (you can run it without downtime). sp_updatestats can be run against a live database without downtime.

如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)

最终,我们选择了使用Spark Framework for Java实现的后端REST API。 这可能不是最强大的,用户反馈一直是个问题。 我们将命令行界面拆分为提交REST调用,并将结果显示给用户。 Ultimately, we chose to go the route of having a backend REST API that was implemented with the Spark Framework for Java. This may not be the most r

AESGCM解密失败的MAC(AESGCM decryption failing with MAC)

您不能将Encoding.UTF8.GetString应用于任意二进制数据。 它只能解码使用UTF-8编码字符串的结果的字节。 .net实现将默默地破坏数据,而不是默认情况下抛出异常。 您应该使用Base64: Convert.FromBase64String和Convert.ToBase64String You can't apply Encoding.UTF8.GetString to arbitrary binary data. It can only decode bytes that

Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)

我希望能看到更多你的Sass代码等,但我的猜测是你需要在所有嵌套行上使用nest行为。 在我看来,基金会在Sass中的行主要是为了在一个层面上使用。 嵌套在另一行中的任何行都应使用nest行为,除非您希望在列上添加额外的填充。 在你的CodePen中,我能够通过向所有行添加一类collapse来修复列上填充的问题,我认为这与执行$behavior: nest相同$behavior: nest在Sass中$behavior: nest :

湖北京山哪里有修平板计算机的

京山有个联想的专卖店,那里卖平板电脑,地址在中百前面的十字路口右拐 ,他们应该会提供相关的维修服务。

SimplePie问题(SimplePie Problem)

我怀疑由于内容的性质(包含代码),stackoverflow提要不起作用。 我使用许多feed解析器看似“正常”的feed有类似的问题,尽管我最近运气最多的是Zend_Feed。 试试吧 I suspect the stackoverflow feed is not working due to the nature of the content (contains code). I have had similar issues with seemingly "normal" feeds us

在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)

是的,您可以通过getApplicationContext()任意数量的时间(后台任务), getApplicationContext()仅返回应用程序的context 。 Yes, you can pass getApplicationContext() any number of time (Background Tasks ) you want, getApplicationContext() simply returns context of the application.

HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)

这是我最终做的事情: 我无法以这种方式提供完全访问权限,而是在project level folder中设置了一个虚拟HTML页面,该页面单击自身以重定向到位于separate, non-project util folder的HTML文件。 这允许我保留除了那个之外的所有内容,非常小的文件分开但不存在文件访问问题。 Here is what I ended up doing: I wasn't able to provide full access exactly this way, but

为什么我会收到链接错误?(Why do I get a linker error?)

看起来您的编译器错误地将名称引入到全局名称空间中,而不是C ++ 11 3.5 / 7中指定的最内层名称空间( Bushman ): 如果没有找到具有链接的实体的块范围声明来引用某个其他声明,那么该实体是最内层封闭名称空间的成员。 代码按照预期在GCC上编译: http : //ideone.com/PR4KVC 你应该能够通过在构造函数的块作用域中声明它之前(或代替它)在正确的名称空间中声明该函数来解决该bug。 但是,我无法访问您的编译器来测试它。 It looks like your co

如何正确定义析构函数(How to properly define destructor)

在C ++中,你需要手动释放内存。 没有垃圾收集器。 您显然需要在析构函数内手动释放内存。 如果您使用new分配内存,则需要对在deconstructor中使用new分配的每个资源使用delete ,例如: class1::~class1(void) { delete resource1; delete resource2; etc... } In C++ you need to free the memory manually. There's no garbage