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
4

1 回答 1

0

我认为这可能会有所帮助:)

  1. 您将需要map在阵列
  2. 使用返回一个新的 TemplateResulthtml
  3. 您想通过创建“完整”动态属性id=${'..'}

这是相关的更改/部分

render() {
  return html`
     ${obj.map((pr)=> html`
       <input id=${`provider-send-${pr.id}`} value=${`trans-${pr.id}`}>Trans
     `)
  `;
}
于 2019-05-21T21:43:53.570 回答