Written by

Question Anas Smith · May 14, 2024

dynaTree looping

Hi Guys

I'm using the below to populate a tree to just show the root with a folder icon but whenever I click on a folder it loops back to the original folder, how can I disable the root folder from expanding to the next, I only want to show the main opened root folder and not to go any further?   

<dynaTree OnGetTreeInfo="GetTreeInfo" showLabel="true" id="editLocTree" onclick="zenPage.setData(zenThis.value)showLines="false"/>


Method GetTreeInfo(pRoot As %String, Output pTree, ByRef pParms) As %Status
{
Set MyId=..GetId,pos=1
&Sql(Select Name,ID into :name,:id from MSDS_COM.Loc where Parent=:MyId)
Set:SQLCODE (name,id)=""
Set pTree(0,"ch",1) = ""
Set pTree(1) = $LB(name,id,1,"","")
Quit $$$OK
}

Thanks

Product version: Ensemble 2018.1

Comments

Vitaliy Serdtsev · May 14, 2024

Try this:

<FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">GetTreeInfo(
  </FONT><FONT COLOR="#ff00ff">pRoot </FONT><FONT COLOR="#000080">As %String</FONT><FONT COLOR="#000000">,
  </FONT><FONT COLOR="#000080">Output </FONT><FONT COLOR="#ff00ff">pTree</FONT><FONT COLOR="#000000">,
  </FONT><FONT COLOR="#000080">ByRef </FONT><FONT COLOR="#ff00ff">pParms</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %Status
</FONT><FONT COLOR="#000000">{
  </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">MyId</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">GetId</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pos</FONT><FONT COLOR="#000000">=1
  </FONT><FONT COLOR="#800080">&Sql(</FONT><FONT COLOR="#0000ff">Select </FONT><FONT COLOR="#008000">Name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">into </FONT><FONT COLOR="#800000">:name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">:id </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">MSDS_COM</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Loc </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">Parent</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">:MyId</FONT><FONT COLOR="#800080">)
  </FONT><FONT COLOR="#0000ff">Set</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">SQLCODE </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">id</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#008000">""
  </FONT><FONT COLOR="#0000ff">if </FONT><FONT COLOR="#800000">pRoot</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">""
  </FONT><FONT COLOR="#800080">{
    </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">pTree</FONT><FONT COLOR="#000000">(0,</FONT><FONT COLOR="#008000">"ch"</FONT><FONT COLOR="#000000">,1) = </FONT><FONT COLOR="#008000">""
    </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">pTree</FONT><FONT COLOR="#000000">(1) = </FONT><FONT COLOR="#0000ff">$LB</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">id</FONT><FONT COLOR="#000000">,1,</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">)
  </FONT><FONT COLOR="#800080">}
  </FONT><FONT COLOR="#0000ff">Quit $$$OK
</FONT><FONT COLOR="#000000">}</FONT>
For further examples, see the class ZENTest.DynaTreeTest in the SAMPLES namespace.
0