React Native通过text / string生成组件

时间:2018-05-31 15:37:29

标签: javascript regex reactjs react-native

我是使用React Native进行编程的新手。我想问一下,是否有通过字符串/文本渲染反应原生组件的最佳方法?

示例中有字符串故事:

var story = "You face the bear please select your action:
[[Choices]]  
[[Choice, Section="1"]] Fight using the sword [[Choice]]
[[Choice, Section="1"]] Use the torch [[Choice]]
[[Choice, Section="2"]] Run Away [[Choice]]
[[Choices]]";

使用此字符串,生成的组件为:

<Text>You face the bear please select your action</Text>
<View>
    <Button title="Fight using the sword" onPress={() => this.goToSection("1")}/>
    <Button title="Use the torch" onPress={() => this.goToSection("1")}/>
    <Button title="Run Away" onPress={() => this.goToSection("2")}/>
</View>

我需要转换来自用户(文本)的输入并自动生成视图的方法。 谢谢。

0 个答案:

没有答案