微信小程序怎样实现点击按钮向数组中添加数据,再次点击删除数组中的改数据,求大神救救我吧! 10
toCollect:function(event){letdish=event.currentTarget.dataset.dish;lettitle=event.cur...
toCollect:function(event){
let dish = event.currentTarget.dataset.dish;
let title = event.currentTarget.dataset.title;
let icon = event.currentTarget.dataset.icon;
var newItem = {
title: title,
icon: icon,
id:dish,
right: 0,
startRight: 0
};
collectItems.push(newItem);
console.log(collectItems);
for (var i = 0; i < collectItems.length; i++) {
// var newCard = [];
// var newCardTeams = [];
// var newCollect = [];
if(collectItems[i]==newItem){
collectItems.slice(0, i).concat(collectItems.slice(i + 1, collectItems.length))
// newCardTeams =collectItems.slice(i + 1, collectItems.length);
// newCollect = newCard.concat(newCardTeams)
this.setData({
collectItems: collectItems
})
} 展开
let dish = event.currentTarget.dataset.dish;
let title = event.currentTarget.dataset.title;
let icon = event.currentTarget.dataset.icon;
var newItem = {
title: title,
icon: icon,
id:dish,
right: 0,
startRight: 0
};
collectItems.push(newItem);
console.log(collectItems);
for (var i = 0; i < collectItems.length; i++) {
// var newCard = [];
// var newCardTeams = [];
// var newCollect = [];
if(collectItems[i]==newItem){
collectItems.slice(0, i).concat(collectItems.slice(i + 1, collectItems.length))
// newCardTeams =collectItems.slice(i + 1, collectItems.length);
// newCollect = newCard.concat(newCardTeams)
this.setData({
collectItems: collectItems
})
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询