简体   繁体   English

react-native renderRow with button:将 rowData 推送到按钮功能

[英]react-native renderRow with button: push rowData to button-function

  • [ 24.1 ] What's the version of React Native you're using? [ 24.1 ] 你使用的是什么版本的 React Native?
  • [ both ] Does this occur on iOS, Android or both? [两者] 这是否发生在 iOS、Android 或两者上?
  • [ Mac ] Are you using Mac, Linux or Windows? [ Mac ] 您使用的是 Mac、Linux 还是 Windows?

I'm doing this:我这样做:

_onPress(data) {
    Actions.shopProducts(data);
}

... ...

renderRow(rowData){
return (
<Button onPress={this._onPress.bind(this)}>
    <View style={styles.row}>
        <View style={styles.listViewContainer}>
            <Image
                source={{uri: rowData.image}}
            />

            <View style={styles.rightContainer}>
                <Text style={styles.smallText}>Name: {rowData.name}</Text>
                <Text style={styles.smallText}>Straße: {rowData.address}</Text>
                <Text style={styles.smallText}>Ort: {rowData.location}</Text>
            </View>
        </View>
    </View>
    </Button>
);
}

... ...

I'm getting following error:我收到以下错误:

Possible Unhandled Promise Rejection (id: 0): undefined is not an object (evaluating 'this._onPress.bind') renderRow @...可能未处理的承诺拒绝(id:0):未定义不是对象(评估'this._onPress.bind')renderRow @...

I'm actually using react-native-router-flux and react-native-button.我实际上使用的是 react-native-router-flux 和 react-native-button。

What causes this error?是什么导致了这个错误? I can't understand this...我无法理解这...

Best regards此致

Edit: Now I want to know how to push the rowData to my Button-function... Any idea?编辑:现在我想知道如何将 rowData 推送到我的按钮功能......知道吗?

Don't forget to 'bind' the renderRow itself , like:不要忘记“绑定” renderRow本身,例如:

<ListView 
  dataSource={this.state.dataSource} 
  renderRow={this.renderRow.bind(this)} 
  ... 
/>

And for passing data to the _onPress method, do this: _onPress数据传递给_onPress方法,请执行以下操作:

<Button onPress={this._onPress.bind(this, rowData)}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM