> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# NodesRef: fields() method

APISummary
Query the attributes of the selected node.

## Syntax

```ts
fields(fields: Record<string, boolean>, callback: (data: object, status: object) => void): SelectorQuery;
```

### Parameters

#### fields

A `Record<string, boolean>`, describing whether it is necessary to query the corresponding type of property.
The range of queryable property types is as follows, and values outside this range will be ignored:

- `attribute` (optional)
  - Only custom attributes will be returned, attributes such as `id`, `class`, `style`, `dataset` will not be returned.
  - Attributes with values `null` / `undefined` / `function` will not be returned.
  - The key of the returned value is in kebab case.

- `class` (optional)

- `dataset` (optional)

- `id` (optional)

- `index` (optional)

- `query` (optional)
  - The `SelectorQuery` object with this node as the root node
    - The query performed on this `SelectorQuery` object is limited to this node and its descendant nodes.
    - Calling `selectRoot()` on this `SelectorQuery` object will return the `NodesRef` object representing this node.

- `tag` (optional)

- `unique_id` (optional)

#### callback

A callback function, the query result will be returned as the parameter of the callback function. The callback function has two parameters:

The first parameter returns the query result.

- If the `NodesRef` represents one single node, it returns a `Record<string, any>` object containing the query result. If the node is not found, it returns `null`.
- If the `NodesRef` represents multiple nodes, it returns an array of `Record<string, any>` objects, each element in the array corresponds to the query result of a node. If no nodes are found, it returns an empty array.

The second parameter returns the status of the query (error message).

### Return Value

Contains the `SelectorQuery` object for this task. Call `exec()` to execute the task.

## Examples

```javascript
lynx
  .createSelectorQuery()
  .select('#id')
  .fields(
    {
      id: true,
      dataset: true,
      tag: true,
    },
    (data, status) => {
      console.log(data, status);
    },
  )
  .exec();
```

Possible output;

```javascript
// data
{"tag":"text","dataset":{"hello":"world"},"id":"my-id"}

// status
{"data":"success","code":0}
```

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.nodes-ref.fields`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/fields.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| fields | Yes (2.8) | Yes (3.4) | Yes (2.8) | Yes (3.7) | Yes (3.7) | No |
| &#96;fields&#96; parameter supporting the &#96;attribute&#96; property | Yes (2.12) | Yes (3.4) | Yes (2.12) | Yes (3.7) | Yes (3.7) | No |

**`fields`**

Query the attributes of the selected node.

- **Web — Not supported:** The Web background runtime does not implement NativeApp.getFields.

**`` `fields` parameter supporting the `attribute` property ``**

`fields` parameter supporting the `attribute` property.

- **Web — Not supported:** The Web background runtime does not implement NativeApp.getFields.

