# SelectorQuery NodesRef.fields(Object fields, function callback)

with Promise style call: Not supported

Mini Program plugin: Support

Gets information about the node. The fields to fetch are specified in fields. The return value is nodesRef Corresponding selectorQuery

# parameter

# Object fields

attribute type Default values Required Introductions Minimum version
id boolean false no Returns a node id
dataset boolean false no Returns a node dataset
mark boolean false no Returns a node mark
rect boolean false no Returns the node layout locationleft right top bottom
size boolean false no Returns the node sizewidth height
scrollOffset boolean false no no Whether to return a node's scrollLeft scrollTopNode must be scroll-view or viewport
properties Array.&ltstring&gt [] no Specifies a list of property names that returns the current property value of the node corresponding to the property name. class style And event - bound property values are not available
computedStyle Array.&ltstring&gt [] no Specifies a list of style names and returns the current value of the node corresponding to the style name 2.1.0
context boolean false no Returns the corresponding node Context object 2.4.2
node boolean false no Returns the corresponding node Node Example 2.7.0

# function callback

callback

# parameter

# Object res

Node related information

# Return value

# SelectorQuery

# Be careful

computedStyle Has a higher priority than Size, when at the same time computedStyle Lee specified width/height And passed in size: True, returns first computedStyle Acquired width/height。

# sample code

Page({
  getFields () {
    wx.createSelectorQuery().select('#the-id').fields({
      dataset: true,
      size: true,
      scrollOffset: true,
      properties: ['scrollX', 'scrollY'],
      computedStyle: ['margin', 'backgroundColor'],
      context: true,
    }, function (res) {
      res.dataset    // DataSet for Node
      res.width      // Width of node
      res.height     // Node height
      res.scrollLeft // Horizontal scrolling position of node
      res.scrollTop  // Vertical scroll position of node
      res.scrollX    // node scroll-x Property's current value
      res.scrollY    // node scroll-y Property's current value
      // Returns the specified style name to be returned here
      res.margin
      res.backgroundColor
      res.context    // Node corresponding Context object
    }).exec()
  }
})