收藏
回答

WXS怎么能获取到data的数据?

<wxs module="test">

module.exports = {

onSroll: function (evt, ownerInstance) {

console.log('滚动事件触发了');

var ds = evt;

console.log('ds',ds)

// 2. 访问具体的数据

var list = ds.shopList; // 对应 data-shop-list

var input = ds.input; // 对应 data-input

var loading = ds.loading; // 对应 data-loading

console.log(list, input, loading,'获取到的数据')

},

};

</wxs>

<view class="container">

<scroll-view class="shopCard-box" type="nested" scroll-x="{{false}}" scroll-y="{{true}}" enhanced :show-scrollbar="false" refresher-enabled="{{true}}" bind:scroll="{{test.onSroll}}" refresher-triggered="{{scrollView_load}}" bindrefresherrefresh="handleRefresherrefresh" bindscrolltolower="handleScrolltolower" data-shop-list="{{shopList}}" data-input="{{inputValue}}" data-loading="{{loadValue}}" prop="{{inputValue}}">

<block wx:if="{{shopList.length > 0}}">

<shopCard class="shopCard" wx:for="{{shopList}}" wx:item="item" wx:index="index" wx:key="{{item.id}}" bind:tap="handleClick" data-item="{{item}}" item="{{item}}" />

</block>

<view wx:else>当前数据为空</view>

<view class="loading" wx:if="{{loadValue}}">加载中...</view>

</scroll-view>

<!-- <view class="zhe" wx:if="{{showPopup}}" bindtap="closePopup">

<view class="popup" hover-class="none" hover-stop-propagation="false">

</view>

</view> -->

</view>


回答关注问题邀请回答
收藏

3 个回答

  • 小黎
    小黎
    01-23

    数据是有的,是因为你获取的对象属性不对,因为(ds.shopList) ds下没有shopList这个属性所以是undefined 

    正确获取:

    ds.currentTarget.dataset.shopList

    对象打印出来是 [object Object] ,正常现象,如果要看具体值转一下就好了

    JSON.stringify(ds.currentTarget.dataset.shopList)

    非对象可直接打印出值,如

    ds.currentTarget.dataset.input

    01-23
    有用
    回复 2
    • 拾壹
      拾壹
      01-23
      谢谢我去试试
      01-23
      回复
    • 拾壹
      拾壹
      01-23
      获取到啦,感谢感谢
      01-23
      回复
  • hello world
    hello world
    01-23

    没法获取,只能把值传过去

    01-23
    有用
    回复 1
    • 拾壹
      拾壹
      01-23
      现在代码就是想用传值的方法,去获取但是还是没获取到
      01-23
      回复
  • 智能回答 智能回答 本次回答由AI生成
    01-23
    有用
    回复
登录 后发表内容