我仍然是React Js的新手,最近我一直在使用PrimeReact进行开发。表单和DataTables对我来说做得很好,但我似乎不知道如何处理下拉列表。我的状态由redux管理,在mapStateToProps i和使用componentDidMount加载我的数据后,我可以console.log并查看我的数据数组。对于普通的react select输入,我使用了以下代码:
const {accounttypes} = this.props;
console.log(accounttypes)
let typesOptions = accounttypes.length > 0
&& accounttypes.map((item, index) => {
return (
<option key={item.id } value={item.id}>{item.name}</option>
)
}, this);这工作作为一个选项,因为我可以张贴到我的后端。然而,我想在我所有的表单中都使用PrimeReact,我一直在为如何去做而苦苦挣扎。以下是我的尝试,它让我头疼:
<div className="p-field p-col-12 p-md-4">
<Dropdown
value={account_type}
optionValue = {accounttypes.id}
optionLabel = {accounttypes.name}
options={accounttypes}
onChange={this.onTypeChange}
placeholder="Select an Acco"
autoFocus = {true}
editable={true}
/>
</div>account_type是我的字段的名称,我的django模型引用了accountytpe模型,并希望在创建Account时捕获account_type。希望有人能帮上忙。提前谢谢你
发布于 2020-07-24 13:23:53
optionLabel和optionValue应该指向对象的等效属性。在你的情况下,我想正确的方法是这样
optionValue="id"
optionLabel="name"https://stackoverflow.com/questions/63067306
复制相似问题