-
23 Dec 2011 5:54 AM #1
Answered: DataView - Question for understanding
Answered: DataView - Question for understanding
Hello,
I have a question about the DataView component in ST. Created it like this:
Everything works like a charm, but if I comment the following two lines out:Code:Ext.define('App.view.HomeDataView', { extend: 'Ext.DataView', xtype: 'home_dataview', config: { defaults: { styleHtmlContent: true }, // Store declaration for tile data store: { fields: ['id', 'name', 'img_url'], data: [ {id: 'tile1', name: 'Blog', img_url: 'img/thumbnail.png'}, {id: 'tile2', name: 'Style Filter', img_url: 'img/thumbnail.png'} ] } , itemTpl: '<h1>test</h1><h2>{name}</h2>' }, initialize: function() { console.log('>> Home_DATA_VIEW [created]'); var data = this.getStore().data.items[0]; console.log(data); this.callParent(); }, });
I get an error like this:Code://var data = this.getStore().data.items[0]; //console.log(data);
Why does this happen? Must the DataView initialized? Where should I initialize the DataView in MVC architecture?Code:Uncaught TypeError: Object [object Object],[object Object] has no method 'each'
Thank you
-
Best Answer Posted by mitchellsimoens
it kind of depends on when the store is applied to the dataview. For instance you shouldn't do this:
You should use the setStoreCode:initialize: function() { this.store = Ext.create('Ext.data.Store', {...}); this.callParent(arguments); }
Code:initialize: function() { this.setStore(Ext.create('Ext.data.Store', {...})); this.callParent(arguments); }
-
23 Dec 2011 7:20 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3109
Looks like this is because the store hasn't translated the data array into a valid Ext.util.MixedCollection yet. I would caution you that you could be sharing the same store for any instance of that class if you define it like that.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
23 Dec 2011 7:40 AM #3
Well is there a better solution or declaration? Sorry my english is not the best and I don't really understand what's wrong here. Want to make a clean DataView in MVC.
Is my solution the only one possible, or should I change it into another one?
-
23 Dec 2011 7:46 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3109
You can set the store in initialize
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
23 Dec 2011 8:22 AM #5
Could you be so kind and give a little code example again? How do I setup the store in the DataView initialize function?
-
23 Dec 2011 8:30 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3109
it kind of depends on when the store is applied to the dataview. For instance you shouldn't do this:
You should use the setStoreCode:initialize: function() { this.store = Ext.create('Ext.data.Store', {...}); this.callParent(arguments); }
Code:initialize: function() { this.setStore(Ext.create('Ext.data.Store', {...})); this.callParent(arguments); }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote