循环生成的button分享无法获取对应参数,从而达到实现分享不同内容?
发布于 4 年前 作者 shaojun 9007 次浏览 来自 官方Issues
  <view class="item-info" wx:for="{{display_all_list}}" wx:for-index="index" wx:key="index">
    <view class="item-into-name-share">
      <view class="item-into-name" bindtap="editRecord" data-index="{{index}}">
        {{item.sup_name}}
      </view>
      <button style="border:none;position: inherit;padding:0rpx;" id="{{index}}" bindtap="onShareAppMessage"
        class="share" open-type="share" data-cust-index="{{index}}" data-no="{{item.supcust_no}}">
        <image src="{{share_logo}}" class="share-image">
        </image>
        分享
      </button>
    </view>
    <view class="item-into-detail" bindtap="editRecord" data-index="{{index}}">
      客户编码: {{item.supcust_no}}
    </view>
    <view class="item-into-detail" bindtap="editRecord" data-index="{{index}}">
      冻结业务:{{item.order_flag==='0'?'正常':'冻结'}}
    </view>
  </view>
js 事件

  onShareAppMessagefunction (e{
    console.log(e)
    console.log(app.globalData.wxgh_oauth_url + '/Image/sygj-logo.png')
    let _this = this;
    if (e.from && e.from === 'button') {
      console.log(e.target.dataset.custIndex)
      let custInfo = _this.data.display_all_list[Number(e.target.dataset.custIndex)];
      
      return {
        title: custInfo.sup_name,
        imageUrl: app.globalData.wxgh_oauth_url + '/Image/sygj-logo.png'
      };

for 循环遍历后  data-cust-index 属性的值是不同的

console 打印的数据,都为for 循环数组的最后一条记录

1 回复

点击的时候增加个二次确认弹窗。弹出二次确认弹窗的时候设置分享内容为你当前这个模块的分享内容。因为点击直接弹出好友列表 这个时候分享内容是设置不上的

回到顶部