如何在React Native中放置某些文本

时间:2019-07-18 18:42:35

标签: react-native text

我正在尝试使用using Microsoft.Azure.Cosmos; using System; using System.IO; using System.Text.Json.Serialization; using System.Threading.Tasks; namespace CosmosTestApp { class Program { const string endpoint = "<REPLACE>"; const string key = "<REPLACE>"; const string dbName = "test"; const string containerName = "items"; public static async Task Main(string[] args) { var options = new CosmosClientOptions() { Serializer = new CosmosJsonSerializer() }; var client = new CosmosClient(endpoint, key, options); var dbResponse = await client.CreateDatabaseIfNotExistsAsync(dbName); var db = dbResponse.Database; var containerDef = new ContainerProperties(containerName, "/id"); var containerResposne = await db.CreateContainerIfNotExistsAsync(containerDef); var testContainer = containerResposne.Container; var testDoc = new TestDoc(); var docResponse = await testContainer.CreateItemAsync(testDoc, new PartitionKey(testDoc.Id)); Console.WriteLine($"Created document {docResponse.Resource.Id}"); var query = testContainer.GetItemQueryIterator<TestDoc>("SELECT * FROM c"); while (query.HasMoreResults) { var doc = await query.ReadNextAsync(); foreach(var x in doc.Resource) { Console.WriteLine($"Retrieved document {x.Id}"); } } } } internal class CosmosJsonSerializer : CosmosSerializer { public override T FromStream<T>(Stream stream) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); stream.Close(); var item = JsonSerializer.Parse<T>(memoryStream.ToArray()); return item; } } //This errors on the SqlQuerySpec public override Stream ToStream<T>(T input) => new MemoryStream(JsonSerializer.ToUtf8Bytes(input)); } internal class TestDoc { [JsonPropertyName("id")] public string Id { get; set; } = "1"; public string TestString { get; set; } = "testing CosmosJsonSerializer"; } } 组件将文本放置在react native中,我想知道如何使用它将Text放置在react native中。我曾尝试将其放置在<->组件中

Text

但这会导致错误和应用崩溃。

我想要的输出是让文本看起来像这样

<Text><-></Text>

但是出现错误。

3 个答案:

答案 0 :(得分:0)

您可以使用反引号``实现所需的功能。可以将保留字符(<或>)作为纯文本插入,如下所示:

<Text>
   {`Process 1 <-> Process 2`}
</Text>

应该可以按照您的预期工作

答案 1 :(得分:0)

要显示Text中的任何字符,请执行

<Text>{"Process 1 <-> Process 2"}</Text>

答案 2 :(得分:0)

< 是文本中唯一无法正常显示的字符,因此在传递变量时必须将其放在花括号中。

<Text><</Text>

<Text>{'<'}</Text>

因此,您可以执行以下操作:

<Text>Process 1 {'<'}-> Process 2</Text>

或类似这样:

<Text>{'Process 1 <-> Process 2'}</Text>