Android 错误:var是保留字-反应本机
我在React Native中创建了一个简单的ListView。我得到一个错误,如图所示。我在网上搜索,但找不到相关的帖子。代码如下所示Android 错误:var是保留字-反应本机,android,react-native,Android,React Native,我在React Native中创建了一个简单的ListView。我得到一个错误,如图所示。我在网上搜索,但找不到相关的帖子。代码如下所示 import React, {Component} from "react"; import {StyleSheet, View, AppRegistry, ListView, Text} from "react-native"; class dhrumil extends Component{ constructor(props){ super(prop
import React, {Component} from "react";
import {StyleSheet, View, AppRegistry, ListView, Text} from "react-native";
class dhrumil extends Component{
constructor(props){
super(props);
this.state = {
var ds = new ListView.DataSource({rowsHasChanged : (r1,r2) => r1!==r2})
return {
dataSource: ds.cloneWithRows(["1","2","3","4","5"])
};
}
}
_renderer(rowData){
return <Text>{rowData}</Text>;
}
render(){
return(
<ListView
dataSource = {() => this.state.dataSource}
renderRow = {() => this._renderer()}
/>
);
}
}
AppRegistry.registerComponent("dhrumil",()=>dhrumil);
如何解决它?您在构造函数中编写了错误的编码
constructor(props) {
super(props);
var ds = new ListView.DataSource({rowsHasChanged : (r1,r2) => r1!==r2})
this.state = {
dataSource: ds.cloneWithRows(["1","2","3","4","5"])
};
}
您的对象文字语法错误。。