Skip to main content
Version: 0.3.x

get_item_of_object

FunctionPrivateSource

data_selected: Any = get_item_of_object(data: Any, index: Any)

Run data[index] supposing that data is abitrary and index can be a one-value sequence.

warning

Note that index is not a route. If it is a sequence, it should only contain one element.

Arguments

Requires

ArgumentTypeRequired
Description
dataAnyThe whole data to be indexed.
indexAnyThe index to be used for finding a part of the data. It can be a number, or a keyword, or a one-value sequence like [0].

Returns

ArgumentType
Description
data_selectedAnyThe part of the data located by the given index.

Examples

Get a part of the whole data

get_a_part_of_data.py
import pprint
from dash_json_grid.mixins import get_item_of_object

data = {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 1111.55,
"batters": {
"batter": [
{"id": "1001", "type": "Regular"},
{"id": "1002", "type": "Chocolate"},
{"id": "1003", "type": "Blueberry"},
{"id": "1004", "type": "Devil's Food"},
]
},
"topping": [
{"id": "5001", "type": "None"},
{"id": "5002", "type": "Glazed"},
{"id": "5005", "type": "Sugar"},
{"id": "5007", "type": "Powdered Sugar"},
{"id": "5006", "type": "Chocolate with Sprinkles"},
{"id": "5003", "type": "Chocolate"},
{"id": "5004", "type": "Maple"},
],
}

index = ["batters"]

pprint.pprint(get_item_of_object(data, index))