【发布时间】:2019-06-28 20:34:37
【问题描述】:
我正在尝试让 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 会显示在屏幕上。
它显示错误“不变违规:文本字符串必须在组件内呈现。”
我正在尝试处理图表,我也尝试过地图,但没有奏效。
React Native 支持地图吗?
【问题讨论】: