【发布时间】:2015-12-13 11:42:36
【问题描述】:
我在 react native 中有一个 ScrollView,它有很多视图。我使用以下代码存储要查看的参考
cards.push(
<Card
ref={(ref) => {
console.log(ref);
this.cardRef[index] = ref;
ref.testMethod();
}} />
);
卡片是一个单独的组件,如下所示:
class Card extends Component {
constructor(props) {
super(props);
this.testMethod = this.testMethod.bind(this);
}
testMethod() {
console.log('this.is.test.method');
}
render() {
return (
<View style={styles.container}>
<Text>This.is.a.card</Text>
</View>
)
}
}
但是它说 testMethod 是未定义的,不能调用 ref.testMethod()。
【问题讨论】:
标签: javascript reactjs react-native