steve589 Posted January 19, 2018 Share Posted January 19, 2018 Hi, is it possible to access the data of a UniTreeNode in javascript on the page? I could not figure out how to do this. Sencha treenode also has a data-property which can be accessed, but this is obviously not the same. I added a value to a UniTreeNode like so: type TNodeInfo = class(TObject) ID: Integer; scrollTo: String; end; procedure addNode(NavTree: TUniTreeView; ID: Integer; sText, sAnchor: String); var Nd: TUniTreeNode; Ni: TNodeInfo; begin Ni := TNodeInfo.Create; Ni.ID := ID; Ni.scrollTo := sAnchor; Nd := NavTree.Items.Add(nil, sText); Nd.Data := Ni; end; In ExtEvents "itemclick" I can access record.data, but my added ID and scrollTo - properties are not available. Thanks for help. Steve Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 21, 2018 Share Posted January 21, 2018 Hi, Yes, it will be available on the server side But, you can try to use this approach for now I think, for example: procedure addNode(NavTree: TUniTreeView; ID: Integer; sText, sAnchor: String); var Nd: TUniTreeNode; Ni: TNodeInfo; begin Ni := TNodeInfo.Create; Ni.ID := ID; Ni.scrollTo := sAnchor; Nd := NavTree.Items.Add(nil, sText); Nd.Data := Ni; with NavTree.JSInterface do begin JSCode(#1'.store.getNodeById('+ IntToStr(TWebTreeNode(Nd).Id) +').data._ID = ' + IntToStr(ID) + ';'); JSCode(#1'.store.getNodeById('+ IntToStr(TWebTreeNode(Nd).Id) +').data._scrollTo = "' + sAnchor + '";'); end; end; function itemclick(sender, record, item, index, e, eOpts) { alert(record.data._ID + ', ' + record.data._scrollTo) } Quote Link to comment Share on other sites More sharing options...
steve589 Posted January 21, 2018 Author Share Posted January 21, 2018 well, something is not working with this solution, I get the alert: "Cannot read property 'data' of null" when I set a breakpoint at O93.store.getNodeById(1).data._ID = 1; and check in the console O93.store.getNodeById(1) the result is null after closing the alert the page is not visible, but when I then check again the console it gives me: constructor {$observableInitialized: true, hasListeners: j, eventedBeforeEventNames: {…}, events: {…}, initConfig: ƒ, …} obviously the object does not exist at load-time yet any Ideas? Quote Link to comment Share on other sites More sharing options...
steve589 Posted January 21, 2018 Author Share Posted January 21, 2018 You wrote: "Yes, it will be available on the server side" Did you mean "Yes, it will be available on the client side"? This would be fine , but there is no need to hurry, I found a very simple solution (rather a hack): I put the anchor hidden in the text property: Nd := NavTree.Items.Add(nil, '<span "' + sAnchor + '">' + sText + '</span>'); and then I can get it like so: NavTree.ClientEvents.ExtEvents.Values['itemclick'] := 'function itemclick(sender, record, item, index, e, eOpts) {' + 'var iPos = record.data.text.indexOf(">") - 1,' + ' anchor = record.data.text.substring(7, iPos),' + ' elTo = ' + UniURLFrame1.JSName + '.iframe.contentWindow.document.getElementById(anchor);' + 'if (elTo) {' + ' ' + UniURLFrame1.JSName + '.iframe.contentWindow.document.scrollingElement.scrollTop = elTo.offsetTop - 5;' + '}' + '}'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.