How to add sources dynamically in GitTree by pushing a button #243
Answered
by
jourdain
perquisite
asked this question in
Q&A
-
I want to add a node dynamically in GitTree by pushing a button. def actives_change(ids):
_id = ids[0]
if _id == "1": # Mesh
state.active_ui = "mesh"
elif _id == "2": #
state.active_ui = "initial_conditions"
elif _id == "3": # Materal
state.active_ui = "material"
elif _id == "4": # Materal
state.active_ui = "calculation_set"
else:
state.active_ui = "nothing"
pipeline1=[
{"id": "2", "parent": "0", "visible": 1, "name": "initial_conditions"},
{"id": "1", "parent": "0", "visible": 1, "name": "mesh"},
{"id": "3", "parent": "0", "visible": 1, "name": "material"},
{"id": "4", "parent": "0", "visible": 1, "name": "calculation_set"},
]
def pipeline_widget():
state.gittree=trame.GitTree(
sources=("pipeline",pipeline1),
actives_change=(actives_change, "[$event]"),
# visibility_change=(visibility_change, "[$event]"),
)
i = 5
def tree_update():
global i
pipeline1.append({"id": "%d"%(i), "parent": "0", "visible": 1, "name": "%d"%(i)})
pipeline2.append({"id": "%d"% (i), "parent": "0", "visible": 1, "name": "%d" % (i)})
i = i + 1
state.pipeline=pipeline1
print('tree update')
with SinglePageWithDrawerLayout(server) as layout:
with layout.drawer as drawer:
pipeline_widget()
with vuetify.VBtn(icon=True, click=tree_update, block=True, variant="outlined") as ok:
ok.set_text("update!") Zhe value of sources of GitTree has changed ,but zhe web interface does't update。 |
Beta Was this translation helpful? Give feedback.
Answered by
jourdain
Apr 23, 2023
Replies: 1 comment 1 reply
-
The problem is that Also there is no point to store the GitTree instance in You can find some related question below: |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jourdain
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is that
state.pipeline
andpipeline1
share the same reference and the change does not get detected. You need to manually callstate.dirty("pipeline")
Also there is no point to store the GitTree instance in
state.gittree
as it can not be used as a variable on the UI side.You can find some related question below: