Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Taro.createSelectorQuery()的api在dataset中获取不到自定义data-的属性 #9302

Closed
const-Ly opened this issue May 10, 2021 · 5 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@const-Ly
Copy link

const-Ly commented May 10, 2021

相关平台

微信小程序

复现仓库

https://github.com/const-Ly/demo/blob/main/demo.tsx
小程序基础库: 2.16.1
使用框架: React

复现步骤

1、运行这个链接的文件:https://github.com/const-Ly/demo/blob/main/demo.tsx
2、查看打印数据中dataset对象中是否包括data-自定义属性

期望结果

使用Taro.createSelectorQuery()的api在dataset中能获取到data-的属性。

实际结果

现在返回的dataset是空对象,dataset对象中并没有data-的属性

环境信息

  Taro v3.2.2


  Taro CLI 3.2.2 environment info:
    System:
      OS: Windows 7
    Binaries:
      Node: 12.8.0 - D:\Program Files\nodejs\node.EXE
      Yarn: 1.22.4 - C:\Users\Administrator\AppData\Roaming\npm\yarn.CMD
      npm: 6.10.2 - D:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels May 10, 2021
@jianqiao0313
Copy link

+1

1 similar comment
@wen-dong
Copy link

wen-dong commented Jul 7, 2021

+1

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 7, 2021

@const-Ly @jianqiao0313 @wen-dong 你不需要用 dataset

refgetElementById 都可以,不需要用 createSelectorQuery

import React from 'react';
import Taro from '@tarojs/taro'

import { View } from '@tarojs/components'


interface defauleState {
  content: string,
}

class Demo extends React.Component<any, defauleState> {
  el = React.createRef(null)

  constructor(props) {
    super(props);
    this.state = {
      content: '',
    }
  }

  onLoad(options) {
    this.getPageData();
  }

  getPageData() {
    Taro.request({
      url: 'https://mock.gezichenshan.top/mock/5b921496de266131e288aaa6/example/ly/collect',
      method:'post',
      success: (res) => {
        console.log(res)
        if(res.data.success == 1) {
          this.setState({
            content: "请求成功"
          }, () => {
            // setTimeout(() => {
              // Taro.createSelectorQuery().selectAll('.container').fields({
              //   dataset: true,
              //   size: true,
              // }, function (res) {
              //   console.log(res)
              // }).exec()
              console.log('ref: ', this.el.current.props)
              const dom = document.getElementById('view')
              console.log('dom: ', dom.props)

            // }, 100);
          })
        }
      }
    }).catch(err => {
    });
  }

  render() {
    const {content} = this.state;
    return <View id='view' ref={this.el} data-index={1} data-id={123} className={'container'}>
      {content}
    </View>
  }
}

export default Demo;

image

@Chen-jj Chen-jj closed this as completed Jul 7, 2021
@dreamthen
Copy link

@Chen-jj 有一个问题,我使用ref如何获取当前dom节点的位置信息?

@dreamthen
Copy link

@Chen-jj 有一个问题,我使用ref如何获取当前dom节点的位置信息?

我的意思就是有没有办法让ref或者getElementById里面的信息与NodeRef里面的逻辑关联起来?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

5 participants