this.setData 在 Object 中,怎么用?

发布于 8 年前作者 tmo11834 次浏览最后编辑 8 年前来自 issues

菜单小程序使用云开发的功能

参数通道配置

let countMsg = "menu[" + groupindex + "].items[" + index + "].count";
let countly = this.data.menu[groupindex].items[index].count;


let foodCountMsg = "menu[" + groupindex + "].foodCount";

let foodCount = this.data.menu[groupindex].foodCount;

this.setData 功能

this.setData({
this.data.menu[groupindex].items[index].count,
          [countMsg]: countly +1,
          [foodCountMsg]: foodCount +1,
    });

结果,foodCountMsg 没有问题。但是 countMsg 在 item Object 数据被删除

1 回复
jiezhao
jiezhao1 楼6 年前

这个问题已经解决了。

下面是我用来解决问题的代码。

this.data.menu[groupindex].items[index].count = countly +1
var count = this.data.menu[groupindex].items[index].count  
e.target.dataset.item.count = this.data.menu[groupindex].items[index].count
 
let menu = this.data.menu;
 
this.setData({
    [foodCountMsg]: foodCount +1,
    menu: menu
});