【问题标题】:How to insert line break in Reacti-Native如何在 React-Native 中插入换行符
【发布时间】:2019-05-27 13:55:10
【问题描述】:

How can I insert a line break into a text component in React Native?

我在这里查看了我的问题。
但我的情况有点不同。
所以它不适用于这种方式。
这是我的容器代码,它为 ContactInfo 提供了道具。

  return data.map( 
    (contact, i) => { 
      return (<ContactInfo contact={contact} key={i} />); 
    } 
  );

这是子组件。它接收道具作为联系人。

      <Text>{this.props.contact.name}</Text>

最后,它给出了结果'name'。
我期待

David
John
Wade

但它给出了“DavidJohnWade”。

我不能将{"\n"} 和` 放入子组件中,因为那只有一行。
我该如何解决这个问题?

【问题讨论】:

  • 嗨,你可以试试这个:{this.props.contact.name + "\n"}
  • 完美运行!!太感谢了
  • 很高兴它为你解决了:)

标签: react-native


【解决方案1】:

因为你传递的是一个字符串,如果你传递{"\n"} 只会将它视为一个字符串。尝试使用javascript方式,在您的contact.name中使用“\n”,例如"David \n John \n Wade"

【讨论】:

    猜你喜欢
    • 2015-12-04
    • 2019-06-12
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多