vue.js 如何制作选择框的下拉选项

m3eecexj  于 2022-12-23  发布在  Vue.js
关注(0)|答案(1)|浏览(126)

我正在构建一个火车网上预订项目,现在我需要构建一个选择框,选项值根据预订表单而变化。

//select-box
<custom-select-box
    label="Travel"
    v-model="form.InfantWithAdult"
    :items="travel"
></custom-select-box>
5uzkadbs

5uzkadbs1#

尝试使用forEach:

travelWith() {
  let travellerlist = [];
  let adults = this.passengers.filter(
    (x) =>
      x.PaxType === "ADT" &&
      x.SSR.Outbound.filter((y) => {
        return y.codeType === "INFT";
      }).length > 0
  );
  if (adults.length > 0) {
    let nr = 1;
    let travel = null;
    // 👇 loop all adults and add to travellerlist array
    adults.forEach(adult => {
      if (!adult.FirstName) {
        travel = `Adult ${nr++}`;
      } else if (adult.FirstName !== "" && adult.LastName !== "") {
        travel = `Adult ${nr++} ${adult.Title} ${adult.FirstName} ${adult.LastName}`;
      }
      travellerlist.push(travel);
    })
  }
  return travellerlist;
},

相关问题