如何在React中拆分DOM中的段落/对象

huangapple go评论58阅读模式
英文:

How to split paragraphs/object in DOM with react

问题

I can help with the translation. Here's the translated code part without any additional information:

const body =
    'We are hiring for the following opportunity:  \n' +
    job.title + ' - ' + job.location + ' \n' +
    job?.description.replace(/<[^>]*>?/gm, '').replace('&nbsp;', ' ').split("<br><br>")[0] + '... \n\n';

If you have any further questions or need additional assistance, please feel free to ask.

英文:

How can i split the context for say if i have the following example? I want to only extract this sentence "Our client, a highly respected moving company is seeking a National Account Move Coordinator to join their team based remotely."

&lt;article&gt;
Our client, a highly respected moving company is seeking a National Account Move Coordinator to join their team based remotely.
&lt;br&gt;
&lt;br&gt;
The successful candidate will have experience within the Household Goods Moving and Relocation Industry.
&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;National Account Move Coordinator responsibilities:&lt;/strong&gt;
&lt;/article&gt;

This is my code at the moment but it does not pull the sentence that i wanted... it pull everything instead..

const body =
    &#39;We are hiring for the following opportunity:  \n&#39; +
    job.title + &#39; - &#39; + job.location + &#39; \n&#39; +
    job?.description.replace(/&lt;[^&gt;]*&gt;?/gm, &#39;&#39;).replace(&#39;&amp;nbsp;&#39;, &#39; &#39;).split(&quot;&lt;br&gt;&lt;br&gt;&quot;)[0] + &#39;... \n\n&#39;;

Please help..

答案1

得分: 1

这样做应该可以:

```YourArticleSelector.innerText``` 应该返回所有文本,而不包括HTML标签,类似于以下内容:

我们的客户,一家备受尊敬的搬家公司正在寻找一名遥远地点工作的全国客户移动协调员。\n
\n\n
成功的候选人将在家庭物品搬迁和搬迁行业拥有经验。\n
\n\n
全国客户移动协调员的职责


现在您可以:

job.description.split(/\n\n/g)[0].trim()


您应该得到您想要的内容
英文:

Well something like this will do

YourArticleSelector.innerText should return all the text without the HTML tags something like

Our client, a highly respected moving company is seeking a National Account Move Coordinator to join their team based remotely.\n
\n\n
The successful candidate will have experience within the Household Goods Moving and Relocation Industry.\n
\n\n
National Account Move Coordinator responsibilities

Now you can just

job.description.split(/\n\n/g)[0].trim()

You should get what you want

huangapple
  • 本文由 发表于 2023年2月26日 23:15:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572937.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定