Novice in react.js and working on a project.
My jsx file is this:
const myFunction= () => {
...
declaring the data in variable called statuses
...
return (
<>
<h4>Show statuses</h4>
<div className="float-left">
Filter
<Dropdown
optionLabel="value"
optionValue="key"
options={statuses}
filterBy="value"
filter
showClear
/>
</div>
</>
);
}
Data in statuses shows like this:
[
{
"key": 1,
"text": "Status 1",
"value": "Status 1"
},
{
"key": 2,
"text": "Status 2",
"value": "Status 2"
},
]
The result i am getting is this:
<ul class="p-dropdown-items" role="listbox">
<li class="p-dropdown-item" aria-label="Status 1" role="option" aria-selected="false">Stlatus 1</li>
<li class="p-dropdown-item" aria-label="Status 2" role="option" aria-selected="false">Status 2</li>
</ul>
My questions are these:
Thank you all in advance
You can map your array and return Dropdown element with appropriate props smth like this in your jsx:
{data.map((obj) => {
return (
<Dropdown
key={obj.key} // should be added
optionLabel={obj.text}
optionValue={obj.value}
options={statuses}
filterBy={obj.value}
filter
showClear
/>
)
})}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.