在 framework7 中访问 smart select 到 javascript 的值

Access the value of smart select via javascript in framwork7

我想通过 javascript 访问智能倍数 select 的值。我没有线索。请帮助某人。 Framework7 smart multiple select

您可以通过使用“.each()”并将其传递给数组来访问多个 selected 值。

例如:

这是倍数select:

<ul>
    <li><a href="#" class="item-link smart-select">
    <!-- "multiple" attribute for multiple select-->
    <select name="car" multiple>
      <!-- options grouped within "optgroup" tag-->
        <option value="honda" selected>Honda</option>
        <option value="lexus">Lexus</option>
        <option value="mazda">Mazda</option>
        <option value="nissan">Nissan</option>
        <option value="toyota">Toyota</option>
    </select>
    <div class="item-content">
      <div class="item-inner">
        <div class="item-title">Car</div>
      </div>
    </div></a></li>
</ul>

正在将 selected 值传递给数组:

var cars = [];
     $$('select[name="car"] option:checked').each(function () {
        cars.push(this.value);
     });

    console.dir(cars); //or console.dir(cars);

结果:(2) ["honda", "lexus"]

老问题,但排名 Google,因为我刚刚在这上面浪费了 2 个小时,所以这里是如何使用 v6 和 vuejs 来解决这个问题:

<f7-list-item title="I feel"
                    class="mood"
                    smart-select
                    :smart-select-params="{openIn: 'popover', closeOnSelect: true}">
        <select name="mood">
          <option value="" selected>Please choose</option>
          <option value="happy">Happy</option>
          <option value="sad">Sad</option>
        </select>
      </f7-list-item>

...

      const mood = f7.smartSelect.get(".mood .smart-select").getValue()

使用 vuejs,f7-list-item 中的 .mood class 被添加到获取 .smart-select class 的元素的父元素中,因此您需要传递两个选择器,否则 f7.smartSelect.get 将无法找到对象。