0

I have a object 'obj' and need to display radio buttons for each object. For each object, two radio buttons are displayed, when i select radio button , for id"trans",it changes/reflects the other

  handleSend(){
    var selected_sendoption = this.shadowRoot.querySelector('input[name = "sending"]:checked').value;
    this.service_send = this.shadowRoot.getElementById("paymentservice_receive");
    this.service_send.innerHTML = selected_sendoption;
    this.selectedsend = selected_sendoption;
  }
render(){
return html`
   ${obj.map((pr)=>{
     <div class="form-check" @click=${this.handleSend}>
       <input class="form-check-input" name="sending" type="radio" id="provider-send-${obj.id}" value="trans">Trans
       <input class="form-check-input" name="sending" type="radio" id="provider-send-${obj.id}" value="insta">Insta
   </div>
<p id="service_send"></p> // display the selected radio button value for corresponding obj selected
   })
  }`;
}
var obj=[
{
    id:"id1",
    in:"trans" 
},
{ 
  id:"id2",
  in:"insta"
}
]
Expected Output:

Display radio buttons for id1

Display radio buttons for id2

Display selected radio buttons for corresponding id
Senthil
  • 961
  • 1
  • 8
  • 21

1 Answers1

0

I think that could help :)

  1. You will need to map over the array
  2. Return a new TemplateResult using html
  3. You want to create a "full" dynamic attribute via id=${'..'}

Here are the relevant changes/parts

render() {
  return html`
     ${obj.map((pr)=> html`
       <input id=${`provider-send-${pr.id}`} value=${`trans-${pr.id}`}>Trans
     `)
  `;
}
daKmoR
  • 1,774
  • 12
  • 24