天津网帮你
小程序判断id来删除数据,长度为0时,显示隐藏部分
时间:2018-07-02 16:09:21 浏览:144

WXML:

 

   {{item.datass}}

   删除

 

 数据删除之后要显示的内容部分

WXSS:

/*遍历循环的数据部分*/

.shuju{

 width: 200px;

 height: 50px;

 line-height: 50px;

 background-color: #188eee;

 color: #fff;

 margin-top: 10px;

 display: flex;

 flex-direction: row;

 text-align: center

}

.shuju>view{

 width: 100px;

 float: left;

}

/*遍历循环的数据没有了要显示的部分*/

.shows{

 width: 100%;

 height: 100px;

 background-color: orangered;

 text-align: center;

 line-height: 100px;

}

JS:

Page({

 data:{

   datas: [

     { datass: 11 },

     { datass: 22 },

     { datass: 33 }

   ]

 },

 deletedata:function(event){

   //获取要删除数据的id

   var dataid=event.currentTarget.dataset.id;

   //找到相对应的数据内容部分

   //var shuju = this.data.datas[dataid];

   //删除数组对应的数据内容

   this.data.datas.splice(dataid,1);

   //判断数据的长度

   var len = this.data.datas.length;

   //通过判断数组的长度来决定是否显示隐藏的部分

   if(len ==0 ){

     this.data.shows =true

   }else{

     this.data.shows = false

   };

   //修改整天数据

   this.setData({

     shows: this.data.shows,

     datas: this.data.datas

   });

 }

})


[上一篇]小程序data数据处理
[下一篇]百度的熊掌号与百家号有什么区别?
Copyright 2025 © wbnsp.com.cn 网帮你

2025 © 版权所有 红花岗区网帮你信息技术工作室

工信部备案号:黔ICP备2025055589号-1

请使用网帮你微信扫码登录