我有一个对象'obj',需要显示每个对象的单选按钮。 对于每个对象,将显示两个单选按钮,当我选择单选按钮时,对于id为“ trans”的对象,它会更改/反映另一个
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
答案 0 :(得分:0)
我认为这可能会有所帮助:)
map
遍历数组html
返回新的TemplateResult id=${'..'}
创建一个“完整”动态属性以下是相关的更改/部分
render() {
return html`
${obj.map((pr)=> html`
<input id=${`provider-send-${pr.id}`} value=${`trans-${pr.id}`}>Trans
`)
`;
}