【问题标题】:Vue and bootstrap drop down select option populated from an array of objectsVue 和 bootstrap 下拉选择选项从对象数组中填充
【发布时间】:2021-09-18 14:43:46
【问题描述】:

我需要一种方法来处理 undefined 和 null

这是引导模板,数据来自名为 dataPlus 的数组,该数组是 Firestore 中的对象数组

-- 选择一个级别 --
      <b-form-select-option
        v-for="(item, index) of $myDb.cart.levels"
        :key="index"
        :value="item.level"
        >{{ item.level }}
      </b-form-select-option>
    </b-form-select>
  </div>

我需要 b-form-select-option 来显示 undefined OR null,因为来自 firestore 的数据可以是任一

【问题讨论】:

    标签: javascript vue.js google-cloud-firestore


    【解决方案1】:

    你是这个意思吗?

    <b-form-select-option
      v-for="(item, index) of $myDb.cart.levels"
      :key="index"
      :value="handleToString(item.level)"
    >
      {{ handleToString(item.level) }}
    </b-form-select-option>
    
    handleToString (val) {
      return ['string', 'number'].includes(typeof val) ? val : (JSON.stringify(val) + '')
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      相关资源
      最近更新 更多