【问题标题】:Passing e.target.value is throwing me error传递 e.target.value 给我带来了错误
【发布时间】:2019-10-20 05:13:08
【问题描述】:

这是我运行 handleUserInputChange 时显示的错误消息。

index.js:1375 MissingMethodException: On_Off_Light.ChangeBrightness 由于:试图访问丢失的成员。

我的功能码:

  handleUserInputChange = e => {
    this.setState({
      brightness: e.target.value
    });
    this.unityContent.send("LightButton", "ChangeBrightness", e.target.value);
  };

我是这样称呼它的:

onChange={this.props.handleUserInputChange.bind(this)}

如你所见,我已经绑定了这个函数,但是当尝试将 e.target.value 作为参数传递给

 this.unityContent.send("LightButton", "ChangeBrightness", e.target.value);

它一直说我正在尝试访问一个丢失的成员。

【问题讨论】:

    标签: reactjs unity3d unity-webgl react-create-app


    【解决方案1】:

    我已经解决了。原来 e.target.value 返回一个字符串值,这不是我想要的。我需要做的就是将其转换为整数,然后才能将其传递给我的统一函数。

    handleUserInputChange = e => {
        this.setState({
          brightness: e.target.value
        });
        this.temp = parseInt(e.target.value)
        this.unityContent.send("LightButton", "ChangeBrightness",this.temp);
      };
    
    

    我会把它留在这里给以后需要的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-25
      • 2013-02-17
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多