如果我有一个像这样的字符串
obj = 1,5,8
并且我有一个嵌套列表,例如(此列表来自数据库,并且在构建表的模型中使用TreeForeignKey
)
objlist= [{"label": "1", "children": [{ "label": "2", "children": [{ "label": "3" }]}]}
{"label": "4","children": [{ "label": "5"},{ "label": "6"}]}
{"label":"7"},
{"label":"8"}]
现在我想基于checked=true
值添加新字段obj
添加字段后,输出将如下所示:
objlist= [{ "label": "1", "children": [{ "label": "2", "children": [{ "label": "3" }]}], "checked":"true"}
{"label": "4","children": [{ "label": "5", "checked":"true"},{ "label": "6"}]}
{"label":"7"},
{"label":"8", "checked":"true"}]
那么如何使用Django实现此输出?
谢谢