Ios React Native with Redux:API对象显示在my console.log中,但不显示在我的视图中
我正在使用Ios React Native with Redux:API对象显示在my console.log中,但不显示在我的视图中,ios,facebook,react-native,redux,react-redux,Ios,Facebook,React Native,Redux,React Redux,我正在使用react,react native,react native router flux,react redux,用redux构建一个简单的体育应用程序,并尝试将顶级新闻对象的api拉到我的视图中。我需要的对象显示在我的控制台日志上,但无法使其显示在我的视图上 我得到的错误是: 无法读取未定义的属性“cloneWithRowsAndSections” TypeError:无法读取的属性“cloneWithRowsAndSections” 未定义 在NewsList.componentWi
react
,react native
,react native router flux
,react redux
,用redux
构建一个简单的体育应用程序,并尝试将顶级新闻对象的api
拉到我的视图中。我需要的对象显示在我的控制台日志上,但无法使其显示在我的视图上
我得到的错误是:
无法读取未定义的属性“cloneWithRowsAndSections”
TypeError:无法读取的属性“cloneWithRowsAndSections”
未定义
在NewsList.componentWillMount
有什么我遗漏的吗
新闻列表:
export default class NewsList extends Component {
constructor(props){
super(props);
const ds = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 != row2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
});
this.state = {
dataSource: ds.cloneWithRowsAndSections(props.ListData)
}
}
componentWillReceiveProps(nextProps){
const dataSource = this.state.dataSource.cloneWithRowsAndSections(nextProps.ListData);
this.setState({dataSource});
}
componentWillMount(){
// console.log("whats This: ",this.props.ListData);
let data = this.props.ListData;
this.setState({
dataSource: this.ds.cloneWithRowsAndSections(data)
});
}
新闻与观点:
render(){
console.log('TopNews', this.state.TopNews);
if(this.state.TopNews.length == 0){
return(
<View style={styles.container}>
<View style={styles.LiveStyle}>
<Live style={styles.LiveStyle} />
</View>
<View style={styles.container}>
<Text style={[styles.NotFollowTeamMsg, styles.centerTeamMsg]}>
Your not connected to the api
</Text>
</View>
</View>
)
} else {
return (
<View style={styles.container}>
<NewsList
ListData={this.state.TopNews}
/>
</View>
)
}
}
然后在NewsList类之外找到它,IsetState
,如下所示:
this.setState({
dataSource: ds.cloneWithRowsAndSections(data)
});
this.setState({
dataSource: ds.cloneWithRowsAndSections(data)
});
但这只会导致错误:
无法读取未定义类型的属性“bind”错误:无法读取
未定义的属性“bind”
2种选择:
1.在构造函数中,将常量ds=…
设为this.ds=…
2.将其从构造函数中取出
函数:
const ds = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 != row2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
});
const ds = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 != row2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
});
并将其定位在新闻列表
类之外
现在,当您设置state
时,按如下方式操作:
this.setState({
dataSource: ds.cloneWithRowsAndSections(data)
});
this.setState({
dataSource: ds.cloneWithRowsAndSections(data)
});
我已经尝试过这两种方法@gran33。出现的错误是:$ds未定义ReferenceError:ds未定义$@check我也收到了您的错误,我的建议对我有效。您的类不知道您的ds
变量,因为您没有将它添加到this.ds=…