繁体   English   中英

将外部Javascript(而非jsx)添加到React Native?

[英]Add external Javascript (not jsx) to React Native?

这里是新的React Native用户。 我试图将下面的Transliterate JS代码从网站添加到React Native。

<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript">

  // Load the Google Transliterate API
  google.load("elements", "1", {
        packages: "transliteration"
      });

  function onLoad() {
    var options = {
        sourceLanguage:
            google.elements.transliteration.LanguageCode.ENGLISH,
        destinationLanguage:
            [google.elements.transliteration.LanguageCode.CHINESE],
        shortcutKey: 'ctrl+g',
        transliterationEnabled: true
    };

    // Create an instance on TransliterationControl with the required
    // options.
    var control =
        new google.elements.transliteration.TransliterationControl(options);

    // Enable transliteration in the textbox with id
    // 'transliterateTextarea'.
    control.makeTransliteratable(['transliterateTextarea']);
  }
  google.setOnLoadCallback(onLoad);
</script>

以下是脚本的HTML代码。

<body>
Type in Chinese (Press Ctrl+g to toggle between English and Chinese)<br>
<textarea id="transliterateTextarea" style="width:600px;height:200px"> 
</textarea>
</body>

如何在React Native中添加使用此代码? 一直为此奋斗了数周。 谢谢!

我将制作一个带有音译来包装元素的高阶组件(HOC)。 您将使用Robbie在对原始问题的注释中引用的库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM