Javascript 为什么即使我指定了值,它仍返回null?
下面的代码返回null,即使我指定了一个特定的值。我认为问题在于Javascript 为什么即使我指定了值,它仍返回null?,javascript,reactjs,Javascript,Reactjs,下面的代码返回null,即使我指定了一个特定的值。我认为问题在于document.getelementbyid('userInput')显然返回null,但我认为这不是100%的情况。 谢谢 从“React”导入React 从“react static”导入{WithRoutedData,Link} // 导出默认WithRoutedData(({Currences})=>( 角隅 克里普托斯 代币 加密/令牌 最小取款数量 最小订单数量 {currency.filter(currency=>
document.getelementbyid('userInput')
显然返回null,但我认为这不是100%的情况。
谢谢
从“React”导入React
从“react static”导入{WithRoutedData,Link}
//
导出默认WithRoutedData(({Currences})=>(
角隅
克里普托斯
代币
加密/令牌
最小取款数量
最小订单数量
{currency.filter(currency=>currency.currency===document.getElementById('userInput').value).map(currency=>(
{currency.currency}
{货币.最低提款额}
{货币.最小订单数量}
))}
))
您可以尝试使用ref而不是document.getElementById来获取值
export default withRouteData(({ currencies }) => (
<div>
<Link to="/">Quoinex</Link>
<Link to="/qryptos"><b>Qryptos</b></Link>
<form id="form">
<input type="text" name="name" placeholder="BTC etc." id="userInput" ref="userInput" value="BTC" />
<input className="sub" type="submit" />
</form>
<h1>Tokens</h1>
<br />
<table className="myTable">
<tr>
<th>Crypto/Token</th>
<th>Min Withdrawal Qty</th>
<th>Min Order Qty</th>
</tr>
{ currencies.filter(currency => currency.currency === React.findDOMNode(this.refs.userInput).value).map(currency => (
<tr key={currency.currency}>
<td id="tokenName">{currency.currency}</td>
<td>{currency.minimum_withdrawal}</td>
<td>{currency.minimum_order_quantity}</td>
</tr>
))}
</table>
</div>
))
export default with routedData(({currencies})=>(
角隅
克里普托斯
代币
加密/令牌
最小取款数量
最小订单数量
{currency.filter(currency=>currency.currency===React.findDOMNode(this.refs.userInput.value).map(currency=>(
{currency.currency}
{货币.最低提款额}
{货币.最小订单数量}
))}
))
export default withRouteData(({ currencies }) => (
<div>
<Link to="/">Quoinex</Link>
<Link to="/qryptos"><b>Qryptos</b></Link>
<form id="form">
<input type="text" name="name" placeholder="BTC etc." id="userInput" ref="userInput" value="BTC" />
<input className="sub" type="submit" />
</form>
<h1>Tokens</h1>
<br />
<table className="myTable">
<tr>
<th>Crypto/Token</th>
<th>Min Withdrawal Qty</th>
<th>Min Order Qty</th>
</tr>
{ currencies.filter(currency => currency.currency === React.findDOMNode(this.refs.userInput).value).map(currency => (
<tr key={currency.currency}>
<td id="tokenName">{currency.currency}</td>
<td>{currency.minimum_withdrawal}</td>
<td>{currency.minimum_order_quantity}</td>
</tr>
))}
</table>
</div>
))