Reactjs 如何在react';s渲染方法

Reactjs 如何在react';s渲染方法,reactjs,Reactjs,我没有问题。。问题是我需要在render方法中调用名为xxx的方法,但我不知道如何调用 方法如下: xxx() { return ( this.state.dataLoadedQuote && <BlogBandLeadershipBlogQuoteItem item={this.state.blogQuote} labels={this.props.labels} /> ); } xxx(){ 返回( this.st

我没有问题。。问题是我需要在
render
方法中调用名为
xxx
的方法,但我不知道如何调用

方法如下:

xxx() {
    return (
        this.state.dataLoadedQuote &&
        <BlogBandLeadershipBlogQuoteItem item={this.state.blogQuote} labels={this.props.labels} />
    );
}
xxx(){
返回(
this.state.dataLoadedQuote&&
);
}

您似乎正确地调用了
xxx()
函数(尽管您不需要传递参数
0
——这是不必要的)。问题可能是,由于您在
xxx()中使用
this
,因此需要在构造函数中绑定函数。否则,
this
将不会引用您的组件,因此
this.state.dataLoadedQuote
将始终是错误的

因此,请加上:

this.xxx = this.xxx.bind(this);
您的构造函数现在可能看起来像:

constructor() {
  super();
  this.state = {}

  this.xxx = this.xxx.bind(this);
}

this.xxx()
在大多数情况下都应该有效,除非您需要绑定
this
。请回答您的问题,让它更清楚地说明您正在尝试做什么。我曾尝试过这种方法,但代码拒绝:render(){return({this.xxx(0)}这是函数:xxx(){return return(this.state.dataLoadedQuote&&)}构造函数在类中,xxx属性是数组。我应该怎么做?导出默认类myClass扩展React.Component{constructor(){super();this.state={xxx:[],