[小程序]遍历并修改数组

that.data.itemSelected.forEach(function(item, index) //开始遍历
{
if(item.name == “xxxxxx” ) //如果等于某值
{
that.data.itemSelected[index].checked = “true”; //修改某值内容

       that.setData({
        itemSelected: that.data.itemSelected 	// 赋回data定义变量,从而改变页面显示
        });
        console.log(that.data.itemSelected[index])
      }
    })
 }

你可能感兴趣的:([小程序]遍历并修改数组)