weixin_58412143 2022-05-19 15:42 采纳率: 90.9%
浏览 1419
已结题

vue JS 怎样根据ID查找所在对象并取出需要的值

如图所示,店铺给的是ID,需要把ID换成另一个接口数据中相对应的值

img


另一个接口数据返回格式

  "info": [
{
"id": 1, //ID
"name": "美妆海外购旗舰店", //名称
},
{
"id": 2, //ID
"name": "美妆海外购旗舰店", //名称
}
] //返回内容
//店铺下拉列表
            storeDown() {
                request({
                    url: "api/shop/getShopList",
                    method: "POST",
                    data: {},
                }).then((res) => {
                    this.storeDownList = res.info
                    console.log('this.storeDownList', this.storeDownList)//下拉列表数据
                })
            },
//查询列表
            getList() {
                request({
                    url: "api/goodsExamine/list",
                    method: "POST",
                    data: this.listQuery,
                }).then(data => {
                    this.list = data.info.content;
                    for (var i = 0; i < this.list.length; i++) {
                        var selectedName = {};
                              selectedName = this.storeDownList.find((item)=>{
                                if(item.id == this.list[i].shopId) {
                                            console.log('item.id',item.id)
                                        }
                                //筛选出匹配数据,是对应数据的整个对象
                              });
                        // selectedName =this.storeDownList.forEach(v => {
                        //     if (v.id == this.list[i].shopId) {
                        //         this.tempUser.shopId=v.name
                        //         console.log('item.id',v.name)
                        //     }
                        // })
                    }
                    console.log('this.list', this.list)//图中四组数据
                    console.log('selectedName', selectedName)//undefined
                })
            },
  • 写回答

2条回答 默认 最新

  • weixin_58412143 2022-07-08 11:10
    关注
    
    handleSelectionChange(selection, row) {
      this.paramsList.forEach((item, index) => {
        if (item.id == row.id) {
          }
      })
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月16日
  • 已采纳回答 7月8日
  • 创建了问题 5月19日

悬赏问题

  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app