Vue.js VueJs:使用数组中的键推送值
我有一个数组Vue.js VueJs:使用数组中的键推送值,vue.js,Vue.js,我有一个数组EventsList。但它没有id列。因此,我需要将带有键的值从EventsList推入List1和List2。我们可以使用下面的代码吗 this.GetEventsList().then(response=>{ if(response.data){ _self.EventsList=response.data; _self.EventsList.forEach (function(events){
EventsList
。但它没有id列。因此,我需要将带有键的值从EventsList
推入List1
和List2
。我们可以使用下面的代码吗
this.GetEventsList().then(response=>{
if(response.data){
_self.EventsList=response.data;
_self.EventsList.forEach (function(events){
if(events.category == "a")
_self.List1.push(events);
else
_self.List2.push(events);
});
}
});
您可以将计数作为id,并将其作为对象推送到列表中。 如果要将项目连续添加到同一列表中,还可以使用当前列表的长度作为id
this.GetEventsList().then(response=>{
if(response.data){
_self.EventsList=response.data;
var count = 0;
_self.EventsList.forEach (function(events){
if(events.category == "a")
_self.List1.push({id:count,events:events});
else
_self.List1.push({id:count,events:events});
count++;
});
}
});
您可以将计数作为id,并将其作为对象推送到列表中。 如果要将项目连续添加到同一列表中,还可以使用当前列表的长度作为id
this.GetEventsList().then(response=>{
if(response.data){
_self.EventsList=response.data;
var count = 0;
_self.EventsList.forEach (function(events){
if(events.category == "a")
_self.List1.push({id:count,events:events});
else
_self.List1.push({id:count,events:events});
count++;
});
}
});
这些活动有什么独特的价值吗?否则,我认为您必须生成自己的密钥。这就是为什么我尝试将ID添加为唯一值事件是否具有唯一值?否则,我认为您必须生成自己的密钥。这就是为什么我试图添加ID作为唯一值