1
當我第二次進入/ view /:id時,我得到了我的組件,它不會檢查收音機。我開始在列表組件中使用react-router作爲網站的索引,我點擊一個元素的視圖按鈕,收音機被選中,我返回到列表中並轉到另一個或相同的元素,並且它不再被檢查。當我在React開發工具中檢查組件時,收音機具有defaultChecked = true屬性。REACT - defaultChecked在第二次加載時不呈現檢查屬性
import React from 'react';
import { connect } from 'react-redux';
class LicenseRadios extends React.Component {
buildRadios() {
let { licenses, activeValue } = this.props;
return licenses.map(license => {
let checked = false;
if(activeValue !== undefined && activeValue === license.id){
checked = true;
}
return (
<div key={license.id} className="col l2">
<p>
<input name="license" type="radio" id={'licenseRdo_' + license.id} value={license.id} defaultChecked={checked} />
<label htmlFor={'licenseRdo_' + license.id}>{license.label}</label>
</p>
</div>
);
});
}
render() {
return (
<div className="row">
{this.buildRadios()}
</div>
);
}
}
export default LicenseRadios;
我試圖改變defaultChecked
爲checked
屬性,但它需要一個onChange事件。我不明白這個問題。有人可以幫我嗎?
謝謝