lit-html选择组件事件处理程序

发布于 2025-02-13 18:50:19 字数 1678 浏览 4 评论 0原文

我正在使用一个名为LIT的库来创建自定义Web组件,并且尝试使用@change@Select事件处理程序来显示另一个组件,没有运气。我似乎也找不到有关文档的信息。

我的代码看起来像这样:

return html`
    <div>
        
        <bx-select helper-text="Optional helper text" @change=${this._updateValue} label-text="Select" placeholder="HIV Test 1 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item 
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.initialTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`)} 
        </bx-select> 

        <bx-select helper-text="Optional helper text" label-text="Select" placeholder="HIV Test 2 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item @change=${this._updateValue}
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.confirmedTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`)}  
        </bx-select>

        <bx-select helper-text="Optional helper text" label-text="Select" placeholder="HIV Test 3 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.finalTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`
          )}  
        </bx-select>
        
    </div>`;

对此的任何帮助/建议将不胜感激。

I am using a library called lit to create custom web components and i have tried using the @change and @select event handlers to display another component with no luck. I also can't seem to find the info on the docs.

My code looks like this :

return html`
    <div>
        
        <bx-select helper-text="Optional helper text" @change=${this._updateValue} label-text="Select" placeholder="HIV Test 1 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item 
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.initialTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`)} 
        </bx-select> 

        <bx-select helper-text="Optional helper text" label-text="Select" placeholder="HIV Test 2 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item @change=${this._updateValue}
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.confirmedTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`)}  
        </bx-select>

        <bx-select helper-text="Optional helper text" label-text="Select" placeholder="HIV Test 3 Results:">
          ${this.answers?.map(
            (item: any) => html`<bx-select-item
              label-text=${item.label}
              value=${item.concept}
              .selected=${this.finalTestVal == item.concept}
            >
              ${item.label}
            </bx-select-item>`
          )}  
        </bx-select>
        
    </div>`;

Any help/ advise on this will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2025-02-20 18:50:20

基于名称&lt; bx-select&gt;我假设您正在使用Carbon Web组件。

不幸的是,它看起来并不像在文档中列出,但是当您选择时触发的事件名称似乎是bx选择选定选择,因此您需要在中添加一个事件侦听器@BX选择选定

可以在这里看到 https:// web-components。 carbondesignsystem.com/?path=/story/components-select-default 当您选择一个选项并查看下面的“动作”选项卡。

您还可以查看组件的源代码以查看事件在此处派遣的位置 https://github.com/carbon-design-system/carbon-web-components/blob/c318f69d726a72f006befc7aa46b76b76b76b76b76b33695d07f/src/src/src/components in href =“ https://github.com/carbon-design-system/carbon-web-components/blob/c318f69d726a72f006befc7a46b76b76b33695507f/src/src/src/components/components/components/components/components/componts/componet/comelect/select.tss.tssuct.tl387” noreferrer“> https://github.com/carbon-design-system/carbon-web-components/blob/c318f69d726a72f006befc7a46b76b76b3695695d07f/src/src/components

Based on the name <bx-select> I'll assume you're using Carbon web components.

Unfortunately it doesn't look like it's listed in the doc but the event name that's fired when you select appears to be bx-select-selected so you'd want to add an event listener with @bx-select-selected.

This can be seen here https://web-components.carbondesignsystem.com/?path=/story/components-select--default when you select an option and see the "Actions" tab below.

You can also see the component's source code to see where the event is dispatched here https://github.com/carbon-design-system/carbon-web-components/blob/c318f69d726a72f006befc7aa46b76b33695d07f/src/components/select/select.ts#L62 and the name is defined here https://github.com/carbon-design-system/carbon-web-components/blob/c318f69d726a72f006befc7aa46b76b33695d07f/src/components/select/select.ts#L387.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文