我正在尝试使用ExtJS 3.4实现自定义商店。 我使用this forum post和ExtJS4版本。
现在我的代码看起来像这样:
<label class="radio-inline">
<input type="radio" ng-model="$parent.switchColors" value = "yes" >Yes</input>
</label>
<label class="radio-inline">
<input type= "radio" ng-model = "$parent.switchColors" value= "no" >No</input>
</label>
我看到了这个错误:
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());
}
});
我的代码中断的部分:
TypeError: this.reader is undefined
如何正确设置读卡器?我想我需要loadData : function(o, append){
var r = this.reader.readRecords(o); <-------
this.loadRecords(r, {add: append}, true);
},
,但我无法正确设置它。我尝试了很多方法......
答案 0 :(得分:0)
ExtJS 3.4的工作代码:
App.store.documents.documentsRandomStore = Ext.extend(Ext.data.Store, {
reader: new Ext.data.ArrayReader(
{
idIndex: 0 // id for each record will be the 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));
}
});