0

I want to call a simple TypeScript function from within an HTML variable. The Button with the HTML is attempting to call '_Myfunction' which creates a simple Alert();.

Clicking on the button produces the following error:

typeError: Cannot read property '_Myfunction' of undefined

How can I resolve this error? And the code is below:

  constructor() {
    super();

  }
  postInitialize(): void {

  }
  render() {
        
    this.mapHelper.map.getSelectedAssets().then(function(resolvedValue) {
        if(resolvedValue != null){

            masterHTMLstring = 
                <table style="background-color:#FFFFFF;width:200px;">
                  {resolvedValue.map((item, index) => (
                    <tr key={index}>     
                       <td>
                        <button id={item.EntityUid} onclick={() => this._myfunction(item.EntityUid)}>Add</button>
                      </td>
                    </tr>
                  ))}
                </table>;


        }   

      }, function(error) {
          //masterHTMLstring = "error";

      });
    return <div class="basemap23"  >{masterHTMLstring}</div>;
  }

  destroy(): void {
    this._handles.destroy();
    this._handles = null;
  }
    
  public _myfunction(entityID: string): void {
    alert(entityID);
  }
objectively C
  • 960
  • 9
  • 25

1 Answers1

1

Replace function(resolvedValue) { with resolvedValue => {

and that should be good

DBA108642
  • 1,995
  • 1
  • 18
  • 55