[英]How to capitalize a Moment component in React-Native
I have the following component:我有以下组件:
<Moment element={Text}
format="MMM DD, YYYY \at h:mma"
style={dateStyle}
>
{this.props.updateDate}
</Moment>
It's currently ouputting something like Jan 01, 2017 at 12:53pm
, but I need it to output JAN 01, 2017 AT 12:53PM
instead.它目前正在输出类似Jan 01, 2017 at 12:53pm
,但我需要它输出JAN 01, 2017 AT 12:53PM
。
Normally you would use {string.toUppercase()}
to achieve this, but I'm having issues figuring out how to get at the output.通常你会使用{string.toUppercase()}
来实现这一点,但我在弄清楚如何获得输出时遇到问题。
Any help would be greatly appreciated.任何帮助将不胜感激。 Thanks!谢谢!
At the time I responded initially in 2017, I was wrong to suggest that one could simply use the CSS text-transform: uppercase
.当我在 2017 年最初做出回应时,我错误地建议人们可以简单地使用 CSS text-transform: uppercase
。 React-Native doesn't use traditional CSS, but uses JavaScript to add styles . React-Native 不使用传统的 CSS,而是使用 JavaScript 添加样式。
At the time, this was not supported by React-Native.当时,React-Native 不支持这一点。 I should have deleted the answer.我应该删除答案。
However, since then, the Text
Component style
property now supports:但是,从那时起, Text
组件style
属性现在支持:
textTransform: 'uppercase'
https://facebook.github.io/react-native/docs/text#style https://facebook.github.io/react-native/docs/text#style
Create your own UpperText
component and pass that to Moment
as element
.创建您自己的UpperText
组件并将其作为element
传递给Moment
。 In your UpperText
component, apply toUppercase()
to its string child and return Text
with the uppercase text.在UpperText
组件中,将toUppercase()
应用于其子字符串并返回带有大写文本的Text
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.