我是Vue js的新手,使用vue-multiselect时,数组对象中的数据如下所示。
[
{
"id": 1,"add_on_type": "Xtra","name": "test","price": 12,"created_at": "2020-06-25 10:12:43","updated_at": "2020-06-25 10:12:43"
},{
"id": 3,"name": "Some x","price": 120,"created_at": "2020-06-30 05:47:52","updated_at": "2020-06-30 05:47:52"
}
]
但是在我的函数中,我需要像下面的key:value
一样访问
"xtra": {
// key: value
0: 1
1: 3
}
但是我得到了所有的数组对象,而不仅仅是id
。我只需要在数组中获取ID
,下面是我的代码。我不知道如何使用下面的代码从id
中仅获取array
。
this.$axios
.get("items/" + this.item)
.then(res => {
// below line is how I get the array object,but I need only id in array.
data.xtra = this.extra;
console.log(data);
})
.catch(err => {
throw err;
});
这对某些人来说可能很容易,但是我找不到解决方法。任何帮助,将不胜感激。预先感谢