React native 无法从JSON数组中提取任何属性 导出默认类主扩展组件{ 构造函数(){ 超级(); const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}) 这个州={ userDataSource:ds, } } componentDidMount(){ 取('http://192.168.0.102/giftbaenew/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=10'{ 标题:{ “授权”:“持票人7dmc9lprh5b1t07hkadyhmtb6etm1jaj” } }) .then((response)=>{return response.json()}) .然后((响应数据)=>{ alert(responseData)//我收到了警报消息。 这是我的国家({ userDataSource:this.state.userDataSource.cloneWithRows(responseData) }) }) } renderRow(用户、sectionId、rowId、highlightRow){ const data=this.state.userDataSource 返回( {data.items[0].name}//错误 ) } render(){ 返回( {this.props.navigation.navigate('Login')}> {/*注销*/} 握手 ) } } const styles=StyleSheet.create({ 容器:{ 背景颜色:“#455a64”, 身高:125 }, 正文:{ textAlign:“左”, 尺寸:25, 颜色:'白色', 玛金托普:0, 边缘左侧:18 } })
我无法在我的应用程序上看到任何内容。 请帮帮我。 items[]是一个JSON数据数组,每个项都有其属性,如名称等 我试图显示名称,但没有显示任何内容。React native 无法从JSON数组中提取任何属性 导出默认类主扩展组件{ 构造函数(){ 超级(); const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}) 这个州={ userDataSource:ds, } } componentDidMount(){ 取('http://192.168.0.102/giftbaenew/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=10'{ 标题:{ “授权”:“持票人7dmc9lprh5b1t07hkadyhmtb6etm1jaj” } }) .then((response)=>{return response.json()}) .然后((响应数据)=>{ alert(responseData)//我收到了警报消息。 这是我的国家({ userDataSource:this.state.userDataSource.cloneWithRows(responseData) }) }) } renderRow(用户、sectionId、rowId、highlightRow){ const data=this.state.userDataSource 返回( {data.items[0].name}//错误 ) } render(){ 返回( {this.props.navigation.navigate('Login')}> {/*注销*/} 握手 ) } } const styles=StyleSheet.create({ 容器:{ 背景颜色:“#455a64”, 身高:125 }, 正文:{ textAlign:“左”, 尺寸:25, 颜色:'白色', 玛金托普:0, 边缘左侧:18 } }),react-native,React Native,我无法在我的应用程序上看到任何内容。 请帮帮我。 items[]是一个JSON数据数组,每个项都有其属性,如名称等 我试图显示名称,但没有显示任何内容。 “错误未定义”不是评估数据的对象。项[0]请尝试我的代码,它将防御性地解决您的问题 export default class Home extends Component{ constructor(){ super(); const ds = new ListView.DataSource({rowHa
“错误未定义”不是评估数据的对象。项[0]请尝试我的代码,它将防御性地解决您的问题
export default class Home extends Component{
constructor(){
super();
const ds = new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2})
this.state={
userDataSource:ds,
}
}
componentDidMount(){
fetch('http://192.168.0.102/giftbaenew/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=10',{
headers:{
'Authorization':'Bearer 7dmc9lprh5b1t07hkadyhmtb6etm1jaj'
}
})
.then((response)=>{return response.json()})
.then((responseData)=>{
alert(responseData) // i get the alert message.
this.setState({
userDataSource:this.state.userDataSource.cloneWithRows(responseData)
})
})
}
renderRow(user,sectionId,rowId,highlightRow){
const data=this.state.userDataSource
return(
<View >
<Text style={{color:'black'}}>
{data.items[0].name} //error
</Text>
</View>
)
}
render(){
return(
<ScrollView>
<View>
<View style={styles.container}>
<TouchableOpacity onPress={()=>{this.props.navigation.navigate('Login')}}>
{/* <Text style={{textAlign:'right',marginTop:5,color:'white',fontSize:16}}>Logout</Text> */}
<Image source={require('../Images/logout.png')} style={{width:30,height:30,marginLeft:325}}/>
</TouchableOpacity>
<Text style={styles.text}>
ShakeHands
</Text>
<TextInput placeholder='Search' placeholderTextColor='black' style={{backgroundColor:'white',marginTop:13,height:35,width:320,marginLeft:20,marginRight:20,padding:10}}/>
</View>
<View style={{marginTop:10}}>
<ListView dataSource={this.state.userDataSource} renderRow={this.renderRow.bind(this)}/>
</View>
</View>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container:{
backgroundColor:'#455a64',
height:125
},
text:{
textAlign:'left',
fontSize:25,
color:'white',
marginTop:0,
marginLeft:18
}
})
import React,{Component}来自'React';
从“react native”导入{FlatList,ActivityIndicator,Text,View};
导出默认类FetchExample扩展React.Component{
建造师(道具){
超级(道具);
this.state={isLoading:true}
}
componentDidMount(){
返回获取('https://facebook.github.io/react-native/movies.json')
.then((response)=>response.json())
.然后((responseJson)=>{
这是我的国家({
孤岛加载:false,
数据来源:responseJson.movies,
},函数(){
});
})
.catch((错误)=>{
控制台错误(error);
});
}
render(){
if(此.state.isLoading){
返回(
)
}
返回(
{item.title},{item.releaseYear}
keyExtractor={(项,索引)=>index}
/>
);
}
}
你能试试这个吗:---this.setState({userDataSource:this.state.userDataSource.cloneWithRows(JSON.parse(responseData))})实际上我想问一下{user.items[0].name}呼叫的方法正确吗?我刚刚意识到我得到了响应,但响应没有在renderRow函数中传输。我解决了它。谢谢你的时间欢迎兄弟快乐编码:P
import React, { Component } from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class FetchExample extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson.movies,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => <Text>{item.title}, {item.releaseYear}</Text>}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}