yysun / apprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
https://apprun.js.org
MIT License
1.18k stars 57 forks source link

How to put 'selected' on <option>? #127

Closed jkleiser closed 2 years ago

jkleiser commented 2 years ago

I'm struggling with a very basic problem. I have created a <select> with a few <option> elements, but I cannot figure out how to make a certain <option> the selected one. I have a function that generates the <option> element, and it currently looks like this:

const renderMyOption = (obj, selNo, i) =>
  selNo == i ?
    <option value={i} selected>{obj.title}</option> :
    <option value={i}>{obj.title}</option>

I have also tried to put the condition and the selected inside the <option>, but I have found no way that works.

yysun commented 2 years ago

selected=true

On Sat, Dec 18, 2021 at 12:06 PM Jon Kleiser @.***> wrote:

I'm struggling with a very basic problem. I have created a to respond correctly. I have now put the condition inside my

const renderMyOption = (obj, selNo, i) => <option value={i} selected={selNo == i}>{obj.title}

— Reply to this email directly, view it on GitHub https://github.com/yysun/apprun/issues/127#issuecomment-997348424, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJUM7BXGXYRTELXP5MFX3URWIGLANCNFSM5KK2T62Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>