Vue JS:在选择下拉菜单中添加可用选项的数量 [英] Vue JS: Add number of available options in select drop down menu

查看:32
本文介绍了Vue JS:在选择下拉菜单中添加可用选项的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在选择下拉菜单中显示每个项目旁边的选项数量.就像例子一样.

I'm trying to display the number of options next to each item in a select drop-down menu. Like in the example.

我的数据是使用 AXIOS 从 JSON 中提取的.这是我数组中一个对象的一行

My data is pulled from a JSON using AXIOS. Here is one line from an object in my array

"Data": {
      "K": "Part Time, Full-time",
    },

和我试图创建的计算属性.它带回了一个数字,但不是我想要的.任何人都可以帮我解决这个问题吗?

and the computed property which I'm attempting to create. It brings back a number but not the ones I would like. Can anyone help me out with this, please?

  computed: {
 feeCount() {
      const feeResults = this.results.filter(
        (result) => result.Data && result.Data.K
      );

      return feeResults.length;
    },
}

推荐答案

你的问题是 "Part Time, Full-time" 是一个字符串,而不是一个数组,所以你得到字符串的长度.

Your problem is that "Part Time, Full-time" is a string, not an array, so you're getting the length of the string instead.

您可以使用 result.Data.K.split(',') 生成一个数组,然后从中计算长度.

You can use result.Data.K.split(',') to generate an array then count the length from that.

这篇关于Vue JS:在选择下拉菜单中添加可用选项的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆