我正在遍历一个基于本机的 <Card dataArray={data} />
组件,使用Buttons渲染了一些组件。一切正常(按预期方式列出了所有组件),但是我很快向onPress
Button添加了一个事件,并得到了一个自动onPress
错误,怪异的是它只运行了一次(单击后便运行了有界函数),而用这些按钮渲染的组件却很多。
//- Inside constructor I bind testLogs
this.testLogs = this.testLogs(this);
//- Outside render...
testLogs(value) {
console.log(value);
}
//- Inside return of render()
<Card dataArray={devices}
renderRow={(theme) =>
<CardItem>
{(theme.picture) ?
<Thumbnail size={100} source={theme.picture} />:
<Thumbnail size={100} source={defaultImage} />
}
<Text style={{fontSize: 16}}> {theme.name} </Text>
<Button primary style={{marginRight: 10}}> Command </Button>
<Button success onPress={this.testLogs} > Edit </Button>
</CardItem>
}>
</Card>
我还应该说,所有渲染的组件在渲染onPress={this.testLogs}
后单击它们时都不会运行绑定功能。
是什么触发了这一点?还是循环渲染不是最好的方法?
谢谢你。
使用onPress = {this.testlogs.bind(this)}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句