我可以点击按钮显示/创建jsTree吗? [英] Can I display/create jsTree on button click?
问题描述
我有一个div id =result
,用于显示用户操作的结果。我也把纯文本和HTML放在那里。每次用户操作后,此div都会被新的结果
覆盖。
I have a div id="result"
that I use to display results of users actions. I put there plain text and html too. After each user action this div is overwritten with new results
.
现在我想在这个div中显示一个 jsTree <的实例/ a>我有工作的jsTree在页面加载时很好地加载但是在< div id =tree>< / div>
被插入后它没有加载在我的结果div中。
Now I want to display inside this div an instance of jsTree I have working jsTree that loads nicely on page load but it doesn't load after <div id="tree"></div>
is inserted inside my result div.
我在下面尝试了两行但没有工作。
I tried two lines below but none worked.
$("#tree").jstree("loaded");
$("#tree").jstree("refresh");
任何想法如何让jsTree在点击按钮后显示 ?请在 jsfiddle 上播放,您可以在其中看到一棵树,我希望在点击后再显示一棵树按钮。我在树之后而不是文本。
Any idea how to make the jsTree to be displayed a after button click? Please play on jsfiddle where you can see one tree already and I want another to be displayed after clicking the button. I am after the tree not the text.
我认为在将hstree div放入html之后我需要重新加载或刷新树。
I think I need to reload or refresh the tree after I place jstree div inside html.
推荐答案
自从< div id =tree2>
以来,第一次创建了tree2当你打电话给'$(#tree2)时没有.jstree'。
tree2 was not created in the first place since <div id="tree2">
was not there when you call '$("#tree2").jstree'.
因此,当您按下按钮时,第一棵树会正确刷新,但由于上述原因,未显示tree2。
So when you press the button, first tree is correctly refreshed but tree2 is not shown for the reason above.
按下按钮,你必须通过调用'$(#tree2)。jstree'来重新创建tree2,或者你可以隐藏< ; div id =tree2>
当你打电话给 $(#tree2)。jstree
。我刚刚更新了你的小提琴( http://jsfiddle.net/fmn6g/10/ ),这样你就可以试试。
At button pressed, you have to recreate tree2 by calling '$("#tree2").jstree', or you can just hide <div id="tree2">
when you call $("#tree2").jstree
. I just updated your fiddle ( http://jsfiddle.net/fmn6g/10/) so you can try.
这篇关于我可以点击按钮显示/创建jsTree吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!