我是 litelement 的新手,我有一个 lit-element 组件,其中渲染时的单选单击事件函数未定义。我想在渲染方法中显示选定的单选按钮值以及相应的提供程序 ID。
render() {
return html`
${this.provider.map(function (provider) {
return html`
<div class="card">
<p>${provider.name}</p>
<div class="form-group">
<div class="form-check pb-2" @click=${this.handleSending}>
<input class="form-check-input" type="radio" name="sending" value="Bank Transfer">
<label>
Bank Transfer
</label><br>
<input class="form-check-input" type="radio" name="sending" value="Credit Card">
<label>
Credit Card
</label><br>
</div>
</div>
</div>`;
})}
`;
}
import { LitElement, html, css } from 'https://unpkg.com/@polymer/lit-element/lit-element.js?module';
export class Provider extends LitElement {
constructor(){
super();
this.provider=[
{
id="1", name="fund" ,description: "Raising Funds"
},
{
id="2", name="transfer" ,description: "transfering money"
}
];
}
handleSending(){
var selected_sendoption = this.shadowRoot.querySelector('input[name = "sending"]:checked').value;
}
render() {
return html`
${this.provider.map(function (provider) {
return html`
<div class="card">
<p>${provider.name}</p>
<div class="form-group">
<div class="form-check pb-2" @click=${this.handleSending}>
<input class="form-check-input" type="radio" name="sending" value="Bank Transfer">
<label>
Bank Transfer
</label><br>
<input class="form-check-input" type="radio" name="sending" value="Credit Card">
<label>
Credit Card
</label><br>
</div>
</div>
</div>`;
})}
`;
}
}
预期结果,在渲染 html 中显示单选按钮选择的值