The object becomes an array of the specified format

The format of the object obtained (there are many attributes in an object)

The data format you want to convert to (an array with multiple objects, each object has an id and name properties)

how to deal with

selectionChange(val) { // 列表选择
                var dynamicTags1 = [];
                var arr=[]
                for(var i= 0;i<val.length;i++){
                    console.log(val[i])
                    var item = {};//定义一个空对象
                    arr.push(val[i].id);
                        item['id'] = val[i].id;//给对象添加id属性并赋值
                        item['name'] = val[i].name;//给对象添加name属性并赋值
                    dynamicTags1.push(item);//再将循环遍历得到的对象追加到数组
                    this.dynamicTags=dynamicTags1;
                    console.log(this.dynamicTags)
                }
                this.leader_id=arr.toString();
            },

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324875975&siteId=291194637