如何在 vuejs 或 Javascript 中查找数组中的元素

Nit*_*mar 3 javascript vue.js vuejs2

我有一个元素数组vuejs,我对它们进行了一些数据操作,就像我有一个显示公司信息的选择下拉列表,每个公司信息都有一个标签。标签属于一个子级别,我已将这两个标签作为一个加入并存储在数据库中,每当我选择母公司时,我希望选择这些标签,我的意思是它应该有类btn-warning,其余的都btn-primary不要与其他选择混淆,有些选项来自第一个选择的过滤器

因此,假设我的标签数据值为:Investor-Mutual fund,它应该分开,并且Investor应该选择按钮,并且Mutual Fund按钮应该具有类别btn-primary,并且只能通过选择列表来更改

这是我的代码笔:https://codepen.io/anon/pen/eWXPaK?editors =1010

这会让你知道我想做什么。引导我

Ber*_*ert 5

我相信这就是你想要的。

if (!this.selectedCompanies.length > 0){
  const str = this.model.data.find(d => d.name === newValue.label)
  const [currentTag, selectedTag] = str.tag.split("-")
  this.currentTag =  currentTag
  this.selectedTag =  this.tags[this.currentTag].find(t => t.display === selectedTag)
}
Run Code Online (Sandbox Code Playgroud)

更新了