我處於學習React Native和Redux的過程中,在這裏有許多類似的問題,但我很難與我的問題聯繫起來。React Native this.'function'不是函數
當我在另一個方法中調用一個方法時,它會一直返回我this.'some函數'不是一個函數,我真的不知道該怎麼做。
下面是我的一些代碼..
import React, { Component } from 'react';
import { Text, StyleSheet, ScrollView } from 'react-native';
import { connect } from 'react-redux';
import Panel from '../components/panel';
class Orders extends Component {
displayItems(obj) {
console.log('itemArr', obj);
return obj.items.map(function(item){
return (<Text>{item.quantity + ' ' + item.name}</Text>)
});
}
renderContents() {
console.log('orders', this.props.orders);
if (!this.props.orders) {
return <Text>Loading...</Text>;
}
return this.props.orders.map(function(order) {
return (
<Panel title={order.id} key={order.id}>
<Text>
Item: {this.displayItems(order)}{'\n'}
</Text>
</Panel>
);
});
}
render() {
return(
<ScrollView style={styles.container}>
{this.renderContents()}
</ScrollView>
);
}
}
我不知道爲什麼渲染方法內的功能不會導致任何錯誤,但在我的renderContents方法執行函數調用。
我欣賞任何建議來解決這個問題。
謝謝先進。
'道具'從哪裏來?你可以添加整個代碼嗎? –