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
)类型。若该值是序列,该序列只能包含单元素。
参数
输入
参数 | 类型 | 必选 | |
---|---|---|---|
data | Any | 需要索引的完整数据。 | |
index | Any | 用来索引并删除数据某一部分的下标值。该值可以是数字、关键字、或者是形如[0] 的单元素序列。 |
输出
参数 | 类型 | |
---|---|---|
data_selected | Any | 由index 定位、并从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)
{'batters': {'batter': [{'id': '1001', 'type': 'Regular'},
{'id': '1002', 'type': 'Chocolate'},
{'id': '1003', 'type': 'Blueberry'},
{'id': '1004', 'type': "Devil's Food"}]},
'id': '0001',
'name': 'Cake',
'ppu': 1111.55,
'type': 'donut'}
[{'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'}]