PDA

View Full Version : Refreshing a Treepanel



neurodon
23 Oct 2012, 10:29 AM
I'm trying to refresh a TreePanel so any records updated in the store will sync:



panel.getStore().sync();
panel.getStore().load();
panel.getView().refresh();


My TreeStore has 'clearOnLoad' set to false.

The behavior is erratic with this.. what happens is the updated row is successfully added.. but one of the existing rows is duplicated in the view.

For example (this is a threaded comment system):

Original store/view:

[[
Comment1
Comment2
Comment3
Comment4
]]

<User adds comment to the store: CommentNEW>
<Application triggers store update - sync,load,refresh>

The TreeView now displays:
[[
Comment1
Comment2
Comment3
Comment4
CommentNEW
Comment1
]]

Any thoughts?

James Goddard
23 Oct 2012, 11:29 AM
Check your id property and values.

Comment 1 cannot be duplicated in the tree unless both have different id's.

neurodon
23 Oct 2012, 11:56 AM
Yeah, thats got to be it.. I'm getting an exception whenever the "error" load happens.

Uncaught TypeError: Cannot read property 'internalId' of undefined

My model has 'internalId' set to my 'eventid' property - which is a GUID style string. I've checked the output from the server.. and all the properties are unique. There is something getting lost in translation between tree loads.

If I can find the source of this exception, I can solve the ID problem... hmm..

P.S: Here is a stack trace of the error.

39549

James Goddard
23 Oct 2012, 12:07 PM
.. and all the properties are unique


Not exactly sure what you are saying here but if what you are saying is that the ID is always unique, this will cause your issue.

For example:
in the initial load Comment 1 has an id of xxxx, Commment 2, yyyy, etc
on the reload Comment 1 has an id of qqqq.

As far as the store is concerned you have 2 records with the name "Comment 1" because xxxx != qqqq.

Comment 1 needs to ALWAYS have the same id, which must be unique to other records.