<分区>
我想将一些基本片段转换为 JavaScript,只是我自己编写的纯 Python 为纯 JavaScript。外面有什么东西吗?这是代码。
items = init['items']
itemsKeyedById = {i["id"]: i for i in items} # hard to convert.
for item in items:
if item["parents"][0]['isRoot'] == False:
parent = itemsKeyedById[item["parents"][0]['id']]
if "children" not in parent:
parent["children"] = []
parent["children"].append(item)
topLevelItems = [item for item in items if item["parents"][0]['isRoot'] == True] # hard to convert.
try:
return json.dumps(topLevelItems[0]);
except:
return '[]'
@Davide: Sadly this question has been closed, otherwise I'd write an answer instead of a comment. The best way to do have python as client side these days is with https://github.com/qquick/Transcrypt