查找数组中符合条件的对象
let val = 1; let list = [ {id:1,name:'张三'}, {id:2,name:'李四'}, {id:3,name:'王五'}, ]; let arr = list.filter((i) => { return val == i.id; });
根据id找出数组里的对象
dsChange(id){ let selectedName = {}; selectedName = this.dsOptions.find((item)=>{ return item.dsid === id; //筛选出匹配数据,是对应数据的整个对象 }); this.formModel.ds = selectedName.ds this.formModel.dsid = selectedName.dsid },
以上为个人经验,希望能给大家一个参考,也希望大家多多支持阿兔在线工具。