lowdefy/packages/docs/operators/_index.yaml
2021-02-12 13:53:31 +02:00

65 lines
2.6 KiB
YAML

# Copyright 2020-2021 Lowdefy, Inc
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_ref:
path: templates/operators.yaml.njk
transformer: templates/operatorsMethodTransformer.js
vars:
pageId: _index
pageTitle: _index
filePath: operators/_index.yaml
types: |
```
(key: string): any
(key: integer): any
(all: boolean): any
(arguments: {
all?: boolean,
key?: string | integer,
default?: any
}): any
```
description: |
The `_index` operator gets a value from the `list indices` array of a block. The `list indices` array is an array of the indices of all [`list`](/lists) block areas which the block is a part of.
arguments: |
###### integer
If the `_index` operator is called with a integer argument, the value at that index in the `indices` array is returned. If the value is not found, `null` is returned..
###### string
If the `_args` operator is called with a string argument, the value at that index in the `indices` array is returned. If the value is not found, `null` is returned.
###### boolean
If the `_index` operator is called with boolean argument `true`, the entire `indices` array is returned.
###### object
- `all: boolean`: If `all` is set to `true`, the entire `indices` array is returned. One of `all` or `key` are required.
- `key: string | integer`: The value of the index in the `indices` array is returned. If the value is not found, `null`, or the specified default value is returned. One of `all` or `key` are required.
- `default: any`: A value to return if the `key` is not found in `arguments`. By default, `null` is returned if a value is not found.
examples: |
###### Get a index:
Assuming the block is in the fourth content area of a `list` block.
```yaml
_index: 0
```
Returns: `3`
###### Get all indices:
Assuming two nested list blocks, with the block in the fourth content area of the first `list` block, and the first content area of the nested `list` block.
```yaml
_index: true
```
Returns: `[3, 0]`