<view wx:if="{{resourceList.length}}"> <view wx:for="{{resourceList}}" wx:key="index"> <view class="resource-item" bindtap="copyLink">{{item.title}}</view> </view> </view> <view wx:else> <view class="no-resource">暂无资源</view> </view>这是它的wxml文件,哪里有问题吗
时间: 2023-08-04 20:09:27 浏览: 18
根据你提供的WXML代码,发现在列表项中没有设置data-title属性,而是直接在列表项中显示了资源的标题。这样会导致在copyLink方法中无法通过e.currentTarget.dataset.title获取到当前点击的列表项的标题,从而无法查找对应的资源对象,也就无法复制链接。
可以将WXML代码修改为如下形式,添加data-title属性,并将资源的标题显示在列表项的内容中:
```
<view wx:if="{{resourceList.length}}">
<view wx:for="{{resourceList}}" wx:key="index">
<view class="resource-item" data-title="{{item.title}}" bindtap="copyLink">{{item.title}}</view>
</view>
</view>
<view wx:else>
<view class="no-resource">暂无资源</view>
</view>
```
修改后,当用户点击列表项时,会将该列表项的标题保存在data-title属性中,然后在copyLink方法中可以通过e.currentTarget.dataset.title获取到该标题,并查找对应的资源对象,从而复制链接。
相关问题
这段代码不显示库存,请进行修改<scroll-view scroll-y> <view wx:if="{{cartList&&cartList.length>0}}"> <view class="list_root"> <block wx:for="{{cartList}}" wx:key="index"> <view class="caipin_item"> <image class="cai_img" src="{{item.icon}}" /> <view class="cai_root2"> <view class="cai_title">{{item.name}}</view> <view class="cai_sell">库存:{{item.num}} </view> <view class="price-stepper"> <view class="cai_price">{{item.price}}</view> <view class="stepper"> <view catchtap="minusCount" data-item="{{item}}"> <image class="jiajian" src="/image/jian.png" /> </view> <view class="value" data-id="{{item._id}}"> {{item.quantity}}</view> <view catchtap="addCount" data-item="{{item}}"> <image class="jiajian" src="/image/jia.png" /> </view> </view> </view> </view> <icon class="shopcart_delete" type="clear" size="18" data-index="{{index}}" data-id="{{item._id}}" catchtap="deleteOne" /> </view> </block> </view>
可以尝试将代码中的 `<view class="cai_sell">库存:{{item.num}} </view>` 修改为 `<view class="cai_sell">库存:{{item.stock}} </view>`,其中 `stock` 为商品的库存属性名,需要根据实际情况进行修改。如果还是不显示库存,可以检查一下数据源中是否有库存属性并且数量正确。
解释这段代码<scroll-view scroll-y> <view wx:if="{{cartList&&cartList.length>0}}"> <view class="list_root"> <block wx:for="{{cartList}}" wx:key="index"> <view class="caipin_item"> <image class="cai_img" src="{{item.icon}}" /> <view class="cai_root2"> <view class="cai_title">{{item.name}}</view> <view class="cai_sell">库存:{{item.num}} </view> <view class="price-stepper"> <view class="cai_price">{{item.price}}</view> <view class="stepper"> <view catchtap="minusCount" data-item="{{item}}"> <image class="jiajian" src="/image/jian.png" /> </view> <view class="value" data-id="{{item._id}}"> {{item.quantity}}</view> <view catchtap="addCount" data-item="{{item}}"> <image class="jiajian" src="/image/jia.png" /> </view> </view> </view> </view> <icon class="shopcart_delete" type="clear" size="18" data-index="{{index}}" data-id="{{item._id}}" catchtap="deleteOne" /> </view> </block> </view> <!--页面底部区域 --> <view class="bottom_box"> <view class="bottom_left" bindtap="goFood">继续选菜</view> <view class="all_money">总计:{{totalPrice}}元,共{{totalNum}}件</view> <view class="choose_ok" bindtap="gotoOrder">去支付</view> </view> </view> <view wx:else class="nothing" bindtap="goFood"> 购物车为空,点击即可点餐 </view> </scroll-view>
这段代码是一个微信小程序的页面结构,包含一个滚动视图组件 `<scroll-view>`,并设置了竖向滚动属性 `scroll-y`。其中使用了条件渲染语句 `wx:if` 和 `wx:else`,根据 `cartList` 数组是否存在或长度是否大于0来渲染不同的内容。如果 `cartList` 存在且长度大于0,则渲染购物车列表,包括菜品图片、名称、库存、价格、数量等信息,并提供加减数量、删除菜品等操作。底部区域包括继续选菜、总计金额和去支付等按钮。如果 `cartList` 不存在或长度为0,则渲染提示信息“购物车为空,点击即可点餐”。
相关推荐















