简体   繁体   English

物化选择onChange的未调用

[英]Materialize Select onChange's not calling

My onChange() is not calling using materializecss select . 我的onChange()没有使用materializecss select进行调用。 :

JavaScript: JavaScript:

$(document).ready(function() {
  $('select').material_select();
});

React: 反应:

...

_bar: function(e){
  console.log("I was called");
},

// Render():

<select defaultValue={this.state.foo} onChange={this._bar}>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

...

The funny thing is, if I add the class browser-default , on the select tag, bar() is called. 有趣的是,如果我在select标记上添加了browser-default类,则会调用bar() Any way around this without the class added to select? 在没有添加类选择的情况下,是否可以解决此问题?

Look like you use incompatible tools. 看起来您在使用不兼容的工具。 As usual, you SHOULD NOT use jquery dom functions with react, because in 90 % cases it is useless, it can break some native react logic with virtual dom, and of course it is overhead. 像往常一样,您不应该将带有响应的jQuery dom函数一起使用,因为在90%的情况下,它是无用的,它可能会破坏带有虚拟dom的某些本机反应逻辑,当然这是开销。

Try to use this library: 尝试使用此库:

https://react-materialize.github.io/forms.html https://react-materialize.github.io/forms.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM