ReactJS map function cannot find property of undefined

后端 未结 3 416
情书的邮戳
情书的邮戳 2021-01-16 07:10

I\'m still learning ReactJS. I\'m challenging myself to write a very basic todo app (as one does) and I\'m having an issue calling an onClick function.

var L         


        
3条回答
  •  礼貌的吻别
    2021-01-16 07:54

    The second argument for the map function is a value to define the scope of this when executing the callback.:

    .map( callback( currentValue, index, array), value_for_this/scope_to_run_in )

    So you can modify your map function as follows:

    var items = list.map(function(item){
      return (
        
  • ); }, this);

    You could also use an arrow function which where this is implicitly bound:

    var items = list.map((item) => {
      return (
        
  • ); });

提交回复
热议问题