收藏
回答

怎样删除动态添加的元素

框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 Bug view 微信iOS客户端 6.5 2.20

<block wx:for="{{fenleilist}}" wx:key="idx"   wx:for-index="idx" wx:for-item="data">

<view  class='itemlist'>

<view class='title'><input  type="text" maxlength="30"  confirm-type="done"  bindconfirm="save_fenlei" value="{{data.title}}" placeholder="填写店铺分类名称"  /> </view>

<view class='bianji'> <button size="mini" type="primary">编辑</button> </view>

<view class='del'>   <icon type="clear"  bindtap='del_fenlei'  data-index='{{idx}}'  data-fenlei_id='{{data.id}}'  size="23"/>  </view>

</view>

</block>


<view class='anniu' > <button bindtap='add_fenlei' size="default" type="primary">添加店铺分类</button> </view>




data: {


fenleilist:[]

},

add_fenlei:function(e){


var that = this

const length = that.data.fenleilist.length

that.data.fenleilist = [{ id: length, title: 'title_' + length }].concat(that.data.fenleilist)

that.setData({

fenleilist: that.data.fenleilist

})


},

del_fenlei:function(e){

var that = this

var fenlei_id = e.currentTarget.dataset.fenlei_id;

var index = e.currentTarget.dataset.index;

var fenlei = that.data.fenleilist;

console.log(fenlei.splice(index, 1))

that.setData({

fenleilist: fenlei.splice(index,1)

})



},


回答关注问题邀请回答
收藏
登录 后发表内容