反应本地货币符号不从变量打印 [英] react native currency symbol not printing from variable

查看:85
本文介绍了反应本地货币符号不从变量打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从其货币代码中打印货币符号。

,但不能从变量中使用。

I want to print currency symbol from its currency code.
but it not working from variable.

我的代码:-

render() {
  var currencyCode = "$"
  return (
      <View>
        <Text>{currencyCode}</Text>
        <Text>&#36;</Text>
      </View>
  )
}

输出:-

如果输入静态货币代码,则它可以工作,但不能从

if enter static currency code so it is working but not working from variable.


如何从变量中打印货币符号?

How to print currency symbol from variable?


推荐答案

这个类似的问题说明了所有可用的选项。由于 dangerouslySetInnerHTML 在React Native中不适用,因此只有两个。

This similar question explains all available options. Since dangerouslySetInnerHTML is inapplicable in React Native, there are only two of them.

HTML实体可以专门解码,例如使用 html-实体

HTML entities can be specifically decoded, e.g. with html-entities:

import { Html5Entities } from 'html-entities';
const htmlEntities = new Html5Entities();

...

{htmlEntities.decode(htmlString)}

可以通过不首先存储HTML实体来避免此问题。货币符号是有效的Unicode字符,可以这样存储:

The problem can be avoided by not storing HTML entities in the first place if possible. Currency symbols are valid Unicode characters and can be stored as such:

var currencyCode = "€"; // &#8364;

这篇关于反应本地货币符号不从变量打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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