【发布时间】:2018-10-30 07:00:47
【问题描述】:
我是原生反应的新手。我正在尝试推送到另一个页面。但我说错了
Undefined is not a function(evaluating '_this2._goToProductListing('app.productListing'{title:item.title})')
我的代码是这样的
_renderContent(section, i, isActive) {
return (
<View>
<List>
{section.content.map((item, i) => {
return(
<ListItem containerStyle={styles.categoryLists}
onPress={() => this._goToProductListing('app.productListing',{title:item.title})}
key={i} title={item.title}
/>
);
})}
</List>
</View>
);
}
//Send to product list page
_goToProductListing = (screen,data) => {
this.props.navigator.push({
screen: screen,
title: data.title,
passProps: {
data: data
}
});
};
render() {
return (
<View style={stylesheet.accrodianWraper}>
<ScrollView>
<Accordion
activeSection={this.state.activeSection}
sections={CONTENT}
touchableComponent={TouchableOpacity}
renderHeader={this._renderHeader}
renderContent={this._renderContent}
duration={0}
onChange={this._setSection.bind(this)}
/>
</ScrollView>
</View>
)
}
谁能告诉我我做错了什么?我该如何解决?
导航我使用wix react native navigation,页面app.productListing也注册在index.js中。
我正在使用 react-native-collapsible 制作手风琴,
乙
【问题讨论】:
-
我猜你在这里松散了上下文:
renderContent={this._renderContent} -
什么意思?手风琴内容正在正确显示。只有当我单击该项目以转到下一页时,才会出现错误而不是将我推到下一页
-
@user7747472 - 查看链接问题的答案。您的
renderContent是一种方法。renderContent={this._renderContent}只是传递函数引用,没有任何指示this使用什么。链接的问题答案向您展示了如何确保使用正确的this。 -
@T.J.Crowder,非常感谢 TJ 提供的非常有用的链接。我不知道不知道这个。再次感谢你
标签: javascript reactjs react-native wix-react-native-navigation