如何在ReactJS中输出文本而不将其包装在span中 [英] How to output text in ReactJS without wrapping it in span

查看:255
本文介绍了如何在ReactJS中输出文本而不将其包装在span中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的基于ReactJS的应用程序中,我这样做:

In my ReactJS-based application I do:

var _ = React.DOM;
_.span(null, 'some text', _.select(null, ...));

问题是:'some text'包含在DOM中的其他span元素中。有没有办法避免这种行为,只输出原始文本?

The problem is: 'some text' is wrapped in additional span element in the DOM. Is there any way to avoid this behavior and just output raw text?

要明确:我想输出

<span>some text<select>...</select></span>

<span><span>some text</span><select>...</select></span>


推荐答案

更新:这是现在已修复 React v15(2016-04-06) - 现在评论节点会在每段文字周围添加,但它不再包含在< span> ; tag。

Update: This is now "fixed" in React v15 (2016-04-06) – now comment nodes are added around each piece of text, but it is no longer wrapped in a <span> tag.


我们在此版本中收到了社区的一些惊人贡献,我们想强调一下 Michael Wiencek 此拉取请求特别是a>。感谢Michael的工作,React 15不再在文本周围发出额外的< span> 节点,使DOM输出更加清晰。对于React用户来说,这是一个长期的烦恼,所以接受这个作为外部贡献是令人兴奋的。

We received some amazing contributions from the community in this release, and we would like to highlight this pull request by Michael Wiencek in particular. Thanks to Michael’s work, React 15 no longer emits extra <span> nodes around the text, making the DOM output much cleaner. This was a longstanding annoyance for React users so it’s exciting to accept this as an outside contribution.

全文发行说明。

目前这是React的技术限制;它包装了一个span中的任何浮动文本节点,以便它可以为它分配一个ID并在以后再引用它。在React的未来版本中,希望我们可以删除此限制。

This is currently a technical limitation of React; it wraps any floating text nodes in a span so that it can assign it an ID and refer back to it later. In a future version of React hopefully we can remove this restriction.

这篇关于如何在ReactJS中输出文本而不将其包装在span中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆