如何在litelement中实现select2

我的

我想知道如何使用 litelement 中的图像实现 select2 下拉列表。由于我有动态选项值,如何在 litelement 中使用选项文本框和标志来实现选择

我在下面的源代码中提到过,请知道如何使用 litelement 中动态选项的标志进行选择

//my-element.js
import {
  LitElement,
  html,
  css
} from "https://unpkg.com/@polymer/lit-element/lit-element.js?module";
export class Calculator extends LitElement {
  static get properties() {
    return {
      otherCountries: { type: Array }
      };
  }

  constructor() {
    super();
    this.otherCountries = [
      //drop down list
      "Austria",
      "Belgium",
      "Bulgaria",
      "Cyprus",
      "Czech Republic",
      "Denmark",
      "Estonia",
      "Finland",
    ];
  }


  render() {
    return html`
      <link
        rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
      />

      <form id="form_values" class="form-inline" role="form" autocomplete="off">

              <div class="col-7 form-group mr-auto">
                <div class="arrowicon">
                  <select
                    style="width: 170px"
                    name="sourcecountrycode"
                    class="calcFont form-control"
                    id="sourcecountrycode"
                    @change="${this.sourcecountryChange}"
                    value=""
                  >
                    ${this.countrydata.countries.map(
                      (country, key) => html`
                        <option value=${country.country_code}
                          >${country.country_name}</option
                        >
                      `
                    )}
                  </select>
                </div>
              </div>
        </form>

    `;
  }
}
customElements.define("calculator-home", Calculator);

哈坎

因为 select2 是一个基于 jQuery 的选择框替代品。因此,由于 jQuery 需要访问文档中运行到 shadow DOM 边界的所有节点,因此目前无法可靠地工作。完整的解释在这里

但是您可以使用 lit-html 作为您的代码示例:

演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章