javascript - 在 react-native 中将模板文字插入视图
问题描述
我正在将一个网络应用程序移动到 React-native。我第一次接触 React 世界,所以对于一个全能的初学者来说,这是一个陡峭的学习曲线。
我的 javascript 运行良好。结果是我的 main 函数返回了一个字符串,在 javascript 中,我使用该字符串将图像动态插入到 DOM 中。我想在 React-native 中做同样的事情,但遇到了麻烦。
我从 javascript 得到的结果是这种形式:
`<Image source={require("./images/pad.png")} style={{ width: 40, height: 318, flexDirection: "row" }} /><Image source={require("./images/banana1.png")} style={{ width: 20, height: 318, flexDirection: "row" }} /><Image source={require("./images/banana2.png")} style={{ width: 20, height: 318, flexDirection: "row" }} /><Image source={require("./images/banana3.png")} style={{ width: 20, height: 318, flexDirection: "row" }} />`
所以它具有正确路径和样式的标签。但是,当我尝试将其插入视图时,我得到一个
"Invariant Violation: Text strings must be rendered within a <Text> component."
不是专门寻找书面解决方案,只是希望有人指出我正确的方向。我将模板文字插入到构造函数中,一切正常。
<View>{this.state.bananasStr}</View>
我可以从那里访问它,或者从 javascript 函数作为变量访问它。
解决方案
推荐阅读
- java - 编译器如何知道在提交中使用哪个 lambda(Callable
任务)或在 ExecutorService 中提交(可运行任务)? - mysql - Apache 中的 PHPMyAdmin 500 内部服务器错误
- python - 如何将特定字母添加到变量然后使其成为字符串
- laravel - 尝试使用 laravel 8 获取非对象的属性“id”
- php - Laravel 雄辩错误期望参数 1 在尝试使用 sum 时为字符串
- scikit-learn - 绘制决策树未给出预期结果
- html - 出现不需要的左边距
- python - 如何一次创建多个数组
- html - 如何在移动视图中使 Bulma 框元素中的元素全宽
- react-native - useEffect 在没有刷新的情况下无法在自定义抽屉组件中工作