我试图使config()运行,但是它以某种方式失败了。
import React, {Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class try1 extends Component {
constructor(noofVertices){
super();
this.noofVertices = this.noofVertices
this.edge = {}
this.a = [];}
addVertex(v){
this.edge[v] = {}
}
addEdge(v, w,weight){
if (weight == undefined) {
weight = 0;
}
this.edge[v][w] = weight;
}
config(){
var vertices = [ 'App0', 'App1', 'App2', 'App3', 'App4' ];
// adding vertices
for (var i = 0; i < vertices.length; i++) {
this.addVertex(vertices[i]);
}
// adding edges
this.addEdge('App0', 'App1',1);
this.addEdge('App0', 'App2',1);
this.addEdge('App0', 'App3',1);
this.addEdge('App0', 'App4',1);
this.addEdge('App1', 'App0',1);
this.addEdge('App1', 'App2',1);
this.addEdge('App1', 'App3',1);
this.addEdge('App1', 'App4',1);
this.addEdge('App2', 'App0',1);
this.addEdge('App2', 'App1',1);
this.addEdge('App2', 'App3',1);
this.addEdge('App2', 'App4',1);
this.addEdge('App3', 'App0',1);
this.addEdge('App3', 'App1',1);
this.addEdge('App3', 'App2',1);
this.addEdge('App3', 'App4',1);
this.addEdge('App4', 'App0',1);
this.addEdge('App4', 'App1',1);
this.addEdge('App4', 'App2',1);
this.addEdge('App4', 'App3',1);
this.traverse('App1');
}
traverse(vertex)
{
for(var adj in this.edge[vertex])
this.a.push(this.edge[vertex][adj])
this.a.sort()
//this.updateEdge1('App0');
}
render(){
return (
<View style={styles.container}>
this.config()
<Text>{this.a}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center',
},
}
);
我希望11111将显示在屏幕上。
它显示错误“不变违例:文本字符串必须在组件内呈现”。
我正在尝试处理图形,我也尝试过地图,但这没有用。
反应本地支持地图吗?
请注意您this.a
的财产try1
组件是一个数组:this.a = [];
和你想你的内直接显示该物业的render()
方法,像这样:<Text>{this.a}</Text>
。但是,由于以下原因,这会导致问题:
该render()
方法不支持直接呈现仅数组的返回类型。调用React
组件的render()
方法时,它必须返回以下之一:
<div />
和<MyComponent />
是React元素,分别指示React渲染DOM节点或另一个用户定义的组件。<Child />
模式,其中test为布尔值。)有关更多信息,请查看render()
规范。
还有其他错误在此代码为S,以及:
try1
为Try1
。return
语句之前,因为return语句期望返回实际的视图本身。考虑到这些要点,请尝试遍历this.a
并为数组中的每个Text
元素提供要显示的元素,如下所示:
render() {
this.config();
let aEles = this.a;
return(
<View style={styles.container}>
aEles.map(edge => (
<Text>{edge}</Text>
));
</View>
)
}
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句