As per local testing, 'this' seems to be null inside the row render function. As a result this prevents me from binding a local function on the onPress prop.
I have this render block:
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow}
renderHeader={this._renderHeader}
style={styles.listView} />
);
}
and a local function
_visitEntryDetail() {
console.log('test');
}
then row render
_renderRow(something) {
return (
<TouchableHighlight
style={[styles.textContainer, filestyle.container]}
onPress={this._visitEntryDetail.bind(this)} >
<View>
<Text style={filestyle.text1} >{something.detail}</Text>
<Text style={filestyle.text2} >{something.size}, {something.timestamp}</Text>
</View>
</TouchableHighlight>
);
}
This returns
message: null is not an object (evaluating 'this.$FileList_visitEntryDetail')"
checking "this" on renderRow returns null when replacing code above with:
_renderRow(file) {
console.log(this);
return (
<TouchableHighlight
style={[styles.textContainer, filestyle.filelistcontainer]}
>
with following console output:
RCTJSLog> null
but is fine when
render() {
console.log('inside render. this value is below me');
console.log(this);
return (
<ListView
console
RCTJSLog> "inside render. this value is below me"
RCTJSLog> [object Object]
Can someone please point out what's causing this. Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…