在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML5/ react native onpress事件不觸發(fā)

react native onpress事件不觸發(fā)

import React from "react";

import { View, Text, FlatList, Image, TouchableOpacity } from "react-native";

import BookItem from "./BookItem";
export default class BookList extends React.Component {
  constructor(props) {
    super(props);
    this.navigation = this.props.navigation;
  }
  render() {
    // console.log(this.props.navigation)
    return (
      <FlatList
        data={this.props.data}
        keyExtractor={this._keyExtractor}
        renderItem={this._renderItem}
      />
    );
  }
  _keyExtractor(item, index) {
    return index.toString();
  }
  _renderItem(item) {
    item = item.item;
    return (
      <TouchableOpacity
        onPress={this._goDetail}
      >
        <BookItem data={item} />
      </TouchableOpacity>
    );
  }

  _goDetail() {
    alert(2);
    // this.navigation.navigate("BookDetail");
  }
}

以上代碼,數(shù)據(jù)渲染成功。
但是在TouchableOpacity上綁定的onpress事件點(diǎn)擊,無(wú)反應(yīng)!
剛開(kāi)始搞react--native,不知道代碼哪里寫(xiě)錯(cuò)了,請(qǐng)大神指教下。

回答
編輯回答
我甘愿

_goDetail沒(méi)有綁定作用域

this._goDetail.bind(this)
2018年3月19日 16:32