PDA

View Full Version : Questions on JsonStore/DataView/XTemplate



Ion Tichy
8 Dec 2010, 4:41 AM
Hi,

I'm fairly new to this whole Sencha/ExtJS busines, so please bear with me. I'm currently trying to load a fairly complex data model into a JsonStore to use in a DataView. I got a few questions:

* is it possible to somewhere SEE what the store loaded?
* How do I get to the loaded records?
* What would be the way to render HTML content from the JSON records? XTemplate?
* Can i use XTemplates without data view, from the (parsed) JSON somehow?

Steffen Hiller
8 Dec 2010, 8:45 AM
* is it possible to somewhere SEE what the store loaded?
If your store is accessible by a global var or a storeId, type in your js console:
store.data.items to see all the records that are in the store ... each record also has data property where the actual data of the record resides.


How do I get to the loaded records?
Normally you add a listeners for the 'load' event to your store. To that listeners handlers, you get the loaded records passed, see 'load' event in the store docs.


What would be the way to render HTML content from the JSON records? XTemplate?
Yes, you can define a Panel with a XTemplate like Ext.Panel({ tpl: new Ext.XTemplate ... }) and in your onLoad you call panel.update(data)
Look at the kiva example, I think there they use that approach
The DataView basically handles that for you. It refreshes the view/html automatically when the store updates. You can set a specific itemTpl as well.


* Can i use XTemplates without data view, from the (parsed) JSON somehow?
Yes, see previous answer.

Ion Tichy
9 Dec 2010, 2:30 AM
Thanks!