问题描述
对于 PrimeReact ListBox 实现:
const cities = [
{name: 'New York',code: 'NY'},{name: 'Rome',code: 'RM'},{name: 'London',code: 'LDN'},{name: 'Istanbul',code: 'IST'},{name: 'Paris',code: 'PRS'}
];
<ListBox
optionLabel="name"
optionValue="code"
value={city}
options={cities}
onChange={(e) => setCity(e.value)}
/>
我得到了带有列表项的正确面板。但是如何禁用列表项,例如如果需要禁用 New York 被选中,如何实现?
解决方法
解决方案是传递属性的名称以匹配禁用状态的选项,如下所示:
DateTime Object ( [date] => 2020-08-02 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin )
// sunday
或者一个决定禁用哪个的函数,其中选项是列表中的一个项目,同时列表被迭代
const cities = [
{ name: 'New York',code: 'NY',disabled: true },{ name: 'Rome',code: 'RM' },{ name: 'London',code: 'LDN' },{ name: 'Istanbul',code: 'IST' },{ name: 'Paris',code: 'PRS' },];
<ListBox
optionLabel="name"
optionValue="code"
value={city}
options={cities}
optionDisabled="disabled"
onChange={(e) => setCity(e.value)}
/>