【问题标题】:Trix-editor on change event not working更改事件上的 Trix 编辑器不起作用
【发布时间】:2016-07-07 06:34:59
【问题描述】:

从几天开始,当trix-editor's 内容更改时,我很难触发 tirx-change 事件。但无法找出问题所在。我正在使用 react js 进行查看。 以下是我的代码:

class Desc extends React.Component {   
 handleChangeTrix(event){this.setState({[event.target.description.name]:
    event.target.description.value});
        }
    render(){
      return(
   <div className="container-fluid">
       <form  onSubmit = {this.handleSubmit.bind(this)} 
              className="form-horizontal" >
         <input id="description"
                 name="description"
                 className="form-control"
                 value={this.state.description} 
                 hidden="True" type="hidden">
         </input>
        <trix-editor trix-change={this.handleChangeTrix.bind(this)}
                     classname="trix-content"
                     input="description" 
                     placeholder="Start typing here...." >
    </trix-editor>
<button type="submit">submit</button>
   </form>
</div>);
    }
}

如果您觉得缺少某些细节,请在评论中提问。如果您觉得问题不合适并且值得一票否决,我很想通过您有价值的评论来了解错误。 提前致谢。

【问题讨论】:

  • 我从未使用过 Trix Editor,但您的代码似乎无效。您的浏览器控制台有错误吗?
  • 也许您需要将inputtrix-editor 元素放在表单标签中。因为render 函数只返回一个 div。我想是的。
  • 嗨,这不是完整的代码(实际代码太长)。我只是在此处取了所需的行并将其框起来。可能是因为遗漏了一些括号。请您更具体地说明这个问题。我将尝试改进上述sn-p。我在浏览器控制台中没有收到任何错误。
  • @DangCongCong 它只存在于表单标签中。我将修改代码以提供清晰的图片。谢谢。
  • 我已经更新了问题。我相信它会使问题更加清晰。

标签: javascript html events reactjs rich-text-editor


【解决方案1】:

你调用 setState 是错误的。应该改成

handleChangeTrix(event){this.setState({description:
event.target.description.value});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多