2016-05-02 58 views
1
  • [24.1]你正在使用的React Native的版本是什么?
  • [both]这是发生在iOS,Android还是两者?
  • [Mac]您使用的是Mac,Linux还是Windows?

我这样做:react-native renderRow with button:push rowData to button-function

_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> 
); 
} 

...

我收到以下错误:

Possible Unhandled Promise Rejection (id: 0): undefined is not an object (evaluating 'this._onPress.bind') renderRow @...

我很激动盟友使用react-native-router-flux和react-native-button。

是什么导致了这个错误?我不明白这个...

问候

编辑: 现在我想知道如何rowData推到我的按钮功能...任何想法?

回答

1

不要忘了“绑定”的renderRow本身,如:

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

而对于将数据传递到_onPress方法,这样做:

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

这正是导致错误。非常感谢! – NullPointer

+0

你知道吗,如何将rowData推送到我的函数中? – NullPointer

+0

@AlbanVeliu不要忘记传递'dataSource'属性,看看我更新的答案 – Cherniv