Threaded View
-
27 Dec 2012 3:10 PM #1
Answered: generate random data for a store (MVC)
Answered: generate random data for a store (MVC)
Hey all,
I'm trying to generate a random data set for a store but I'm having trouble. My generator function is undefined, I'm probably declaring it in the wrong place/way or calling it in the wrong way. Here is my code (for my store file).
Any help on this is much appreciatedCode:Ext.define('TR.store.Trends', { extend: 'Ext.data.Store', model: 'TR.model.Trends', generateData : function(){ var data = []; //logic to populate data array missing, for now I am just //pushing a single entry data.push({ name: '2012-12-10', number: 10, percent: 8.7, }); return data; }, data:this.generateData(), });
-
Best Answer Posted by vietits
At defining time of TR.store.Trends, 'this' is often window or some other object, not the store instance which will be existed only when you create an instance of the store. So this.generateData will often be undefined.
Try to fix your code as below:
Code:Ext.define('TR.store.Trends', { extend: 'Ext.data.Store', model: 'TR.model.Trends', generateData : function(){ var data = []; //logic to populate data array missing, for now I am just //pushing a single entry data.push({ name: '2012-12-10', number: 10, percent: 8.7, }); return data; }, // data:this.generateData(), constructor: function(){ this.data = this.generateData(); this.callParent(arguments); } });


Reply With Quote