跳到主要内容
版本:0.4.2

pop_item_of_object

函数私有源码

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

对于任意数据data,取得val = data[index]; del data[index]; return val的结果,其中index可以是一个由单元素构成的序列。

注意

注意index并非是路由(route类型。若该值是序列,该序列只能包含单元素。

参数

输入

参数类型必选
说明
dataAny需要索引的完整数据。
indexAny用来索引并删除数据某一部分的下标值。该值可以是数字、关键字、或者是形如[0]的单元素序列。

输出

参数类型
说明
data_selectedAnyindex定位、并从data删除并弹出的data的一部分。

范例

删除完整数据的某部分

remove_a_part_of_data.py
import pprint
from dash_json_grid.mixins import pop_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"},
],
}

route = "topping"

removed = pop_item_of_object(data, route)
pprint.pprint(data)
pprint.pprint(removed)