javascript - 在我的反应应用程序上使用 selected.js
问题描述
我正在尝试在我的反应应用程序中使用 selected.js。然而,虽然我已经阅读了关于 refs 和 stuffs 的文档(https://reactjs.org/docs/integrating-with-other-libraries.html),但我并没有真正得到它所说的任何内容。什么是 ref 以及它到底做了什么?我有我的反应代码,但它不起作用。如果有人能解释 this ref 和 this.$el 的反应,我将不胜感激。
import React, { Component } from 'react';
import $ from 'jquery';
import { findDOMNode } from 'react-dom';
class Chosen extends Component {
componentDidMount(){
this.el = $(this.el);
this.$el.chosen();
}
componentWillUnmount(){
this.$el.chosen('destroy');
}
render() {
return (
<div>
<select className="Chosen-select" ref={ el => this.el = el }>
{ this.props.children }
</select>
</div>
)
}
}
export default Chosen;
并且,
import React from 'react';
import Chosen from './Chosen';
function Restaurants(props) {
return (
<Chosen className="Chosen-select" onChange={ value => console.log(value) }>
{
[{name: 'h'}, {name: 'j'}, {name: 'k'}].forEach( r => {
<option>{ r.name }</option>
})
}
</Chosen>
);
}
export default Restaurants;
解决方案
推荐阅读
- oracle - 将行插入新表并追加新行
- azure - Azure 应用服务持续集成 MSI 错误 400
- c# - 在子类中调用父类的 Start、Update 等“私有”函数是否正常?
- mysql - Gaia 环境中与 mysql(MariaDB) 的 SQL 冲突
- c++ - 使用 Julia 集的距离估计器得到不好的结果
- c++ - 如何在 Qt 4.8 中阻止/忽略/丢弃早于某个超时的用户输入事件
- ios - 无法更改右导航按钮标题
- docker - Dockerfile 入口点无法切换用户
- java - 带有 jsonpath 的函数 min()、max() 或 sum()
- c++ - 加载 "D:\Users\Public\Documents\opencv\build\x64\vc14\bin\opencv_world340d.dll" ,找不到或无法打开 PDB 文件