2016-05-11 5 views
0

私の反応のアプリケーションで私は以下のようなコードがあります。未定義のremoveOperation。私はのためにエラーがオンラインでチェックしています。関数リファレンスとそれに対する解決策は、.bind(この)私はこのバインドを使用することができる場所 .Plz誰かが私を助けを使用している、私はあなたがいずれかを行うことができ。Reactjsのこの参照エラー

fields = this.state.operations.map(function(operation,index){ 
      if(operation == "adjust-price-multiply"){ 
       return (<PriceMultiply key={index} removeOperation={this.removeOperation} />); 
      }else if(operation == "adjust-price-add"){ 
       return (<PriceAdd key={index} removeOperation={this.removeOperation} />); 
      }else if(operation == "filter-products-includes"){ 
        return (<IncludeProducts key={index} removeOperation={this.removeOperation} />); 
      }else if(operation == "filter-products-excludes"){ 
        return (<ExcludeProducts key={index} removeOperation={this.removeOperation} />); 
      } 
    }); 

答えて

1

をエラーにつながるeverthing多くの方法で試してみましたこの:

01:

fields = this.state.operations.map(function(operation,index){ 
     if(operation == "adjust-price-multiply"){ 
      return (<PriceMultiply key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "adjust-price-add"){ 
      return (<PriceAdd key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "filter-products-includes"){ 
       return (<IncludeProducts key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "filter-products-excludes"){ 
       return (<ExcludeProducts key={index} removeOperation={this.removeOperation} />); 
     } 
}.bind(this)); 

それとも、(()=>{}代わりfunction() {}の)ES6矢印関数の構文を使用しているときthisが自動的にバインドされているES6のtranspiling(バベル)のいくつかの並べ替えをuseingしている場合

fields = this.state.operations.map((operation,index) => { 
     if(operation == "adjust-price-multiply"){ 
      return (<PriceMultiply key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "adjust-price-add"){ 
      return (<PriceAdd key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "filter-products-includes"){ 
       return (<IncludeProducts key={index} removeOperation={this.removeOperation} />); 
     }else if(operation == "filter-products-excludes"){ 
       return (<ExcludeProducts key={index} removeOperation={this.removeOperation} />); 
     } 
}); 
+0

大変ありがとう@マリアス最初の方法はうまくいかず、2番目の方法は完全に機能します – yasar