extjs - Custom store implementing errors -
i'm trying implement custom store extjs 3.4. use this forum post extjs4 version.
now code looks this:
ext.define('teststore', { extend: 'ext.data.store', //model: 'testmodel', fields: [ {name: 'date'}, {name: 'number'}, {name: 'percent'} ], storeid: 'teststore', generatedata: function() { var me = this, data = []; // generate 10 records for( var i=0;i<10;i++) { data.push([ me.randomdate(new date(2012, 0, 1), new date()), math.floor( math.random() * 1000 ), ( ( math.random() * 1000 ) / 3.2 ).tofixed( 1 ) ]); } console.log(data); return data; }, randomdate: function(start, end) { return new date( start.gettime() + math.random() * (end.gettime() - start.gettime()) ); }, constructor: function() { console.log('constructor!'); var me = this; me.superclass.constructor.apply(me, arguments); me.loaddata(me.generatedata(), true); //me.add(me.generatedata()); } });
and see error:
typeerror: this.reader undefined
part code breaks:
loaddata : function(o, append){ var r = this.reader.readrecords(o); <------- this.loadrecords(r, {add: append}, true); },
how correctly set reader? think need arrayreader
, can't set properly. tried ways...
working code extjs 3.4:
app.store.documents.documentsrandomstore = ext.extend(ext.data.store, { reader: new ext.data.arrayreader( { idindex: 0 // id each record first element }, //rt // recordtype ext.data.record.create([ {name: 'date'}, {name: 'number'}, {name: 'percent'} ]) ), storeid: 'documentsrandomstore', generatedata: function(count) { var data = []; // generate records for(var i=0; i<count; i++) { data.push([ this.randomdate(new date(2016, 0, 1), new date()), 'Документ ' + math.floor( math.random() * 100 ), ( ( math.random() * 1000 ) / 3.2 ).tofixed( 1 ) ]); } return data; }, randomdate: function(start, end) { return new date( start.gettime() + math.random() * (end.gettime() - start.gettime()) ); }, constructor: function(count) { app.store.documents.documentsrandomstore.superclass.constructor.apply(this, arguments); this.loaddata(this.generatedata(count)); } });
Comments
Post a Comment