Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过此方法调用该方法(React Native)? renderTopicList(){ //console.log(this.props); //log(this.state.dataSource); 返回( ); } renderTopicListCell(数据){ 返回( 选择主题(数据)} 数据={data}/> ); } 选择主题(数据){ 这个是.props.navigator.push({ 标题:'详细' + (data.replies_count?)(“+data.replies_count.toString()+”条回复)' : ''), 组件:TopicView, 通行证:{ 数据:数据 } }); }_Javascript_React Native - Fatal编程技术网

Javascript 如何通过此方法调用该方法(React Native)? renderTopicList(){ //console.log(this.props); //log(this.state.dataSource); 返回( ); } renderTopicListCell(数据){ 返回( 选择主题(数据)} 数据={data}/> ); } 选择主题(数据){ 这个是.props.navigator.push({ 标题:'详细' + (data.replies_count?)(“+data.replies_count.toString()+”条回复)' : ''), 组件:TopicView, 通行证:{ 数据:数据 } }); }

Javascript 如何通过此方法调用该方法(React Native)? renderTopicList(){ //console.log(this.props); //log(this.state.dataSource); 返回( ); } renderTopicListCell(数据){ 返回( 选择主题(数据)} 数据={data}/> ); } 选择主题(数据){ 这个是.props.navigator.push({ 标题:'详细' + (data.replies_count?)(“+data.replies_count.toString()+”条回复)' : ''), 组件:TopicView, 通行证:{ 数据:数据 } }); },javascript,react-native,Javascript,React Native,在单元格中选择调用: 当我点击单元格时,它给出以下错误:_this3.selectTopic不是一个函数。(在“_this3.selectTopic(数据)”中,“_this3.selectTopic”未定义)您可以通过两种方法解决此问题 1) 在组件构造函数中,可以绑定要传递的函数。例如: renderTopicList(){ // console.log(this.props); //console.log(this.state.dataSource); return

在单元格中选择调用:


当我点击单元格时,它给出以下错误:_this3.selectTopic不是一个函数。(在“_this3.selectTopic(数据)”中,“_this3.selectTopic”未定义)

您可以通过两种方法解决此问题

1) 在组件构造函数中,可以绑定要传递的函数。例如:

renderTopicList(){
    // console.log(this.props);
    //console.log(this.state.dataSource);
    return (
        <ListView
        style={Style.listView}
        ref="listview"
        pageSize={15}
        dataSource={this.state.dataSource}
        renderFooter={this.renderFooter}
        renderRow={this.renderTopicListCell}
       // onEndReached={this.onEndReached}
        automaticallyAdjustContentInsets={false}
        showsVerticalScrollIndicator={false} 
        />
    );
}

renderTopicListCell(data){
    return (
        <TopicListCell
            onSelect = { () => this.selectTopic(data) }
            data={data} />
    );
}
selectTopic(data){

    this.props.navigator.push({
        title: '详细' + (data.replies_count ? '(' + data.replies_count.toString() + '条回复)' : ''),
        component: TopicView,
        passProps: {
            data: data
        }
    });
}
然后,您可以使用传递数据

constructor() {
  super();

  // Binding the function 
  this.selectTopic.bind(this);
}
renderTopicListCell(数据){
返回(
);
}
2) 您可以在传递函数时绑定它

renderTopicListCell(data){
    return (
        <TopicListCell
            onSelect={this.selectTopic(data)}
            data={data} />
    );
}


我更喜欢前一种方法,这样我就可以在一个地方进行所有绑定调用,而且我必须绑定一次。

谢谢您的帮助,我想知道为什么不能在这里使用arrow函数?这个in-arrow函数引用类对象?
<TopicListCell onSelect={this.selectTopic.bind(this, data)} data={data} />