PDA

View Full Version : extend store



dmitry.akatev
5 Nov 2013, 5:25 AM
I know English is bad, so I use a translator.

create a new class 2 store:

Ext.define("Ext.data.Store2",
{
extend: 'Ext.data.Store',
idProperty: 'id',
remoteSort: true,
proxy:
{
type: 'ajax',
actionMethods:
{
read: 'POST'
},
reader:
{
root: 'data',
totalProperty: 'totalCount'
},
simpleSortMode: true
},
sorters: [
{
property: 'id',
direction: 'ASC'
}],

constructor: function(config)
{
this.proxy.url = config.url;
Ext.data.Store2.superclass.constructor.call(this, config);
}
});


create and store:

var store1 = Ext.create("Ext.data.Store2",
{
pageSize: 20,
fields: ['id', 'name'],
url: 'data1.php',
autoLoad: true,
listeners:
{
load:
{
fn: function()
{
console.log(this.model.modelName);
console.log(this.data.items[0].id);
console.log(this.data.items[0].data);
}
}
}
});

var store2 = Ext.create("Ext.data.Store2",
{
pageSize: 20,
fields: ['id', 'datetime_create'],
url: 'data2.php',
autoLoad: true,
listeners:
{
load:
{
fn: function()
{
console.log(this.model.modelName);
console.log(this.data.items[0].id);
console.log(this.data.items[0].data);
}
}
}
});


the result will be as follows:

Ext.data.Store.ImplicitModel-ext-gen1022 settings.js:345
Ext.data.Store.ImplicitModel-ext-gen1021-1 settings.js:346
Object {id: "1", name: ""} settings.js:347
Ext.data.Store.ImplicitModel-ext-gen1021 settings.js:325
Ext.data.Store.ImplicitModel-ext-gen1021-1 settings.js:326
Object {id: "1", name: "google"}

it is not the result I expected.
in the second case, the fields do not take those. takes from the first store. how to write this code?

slemmon
23 Nov 2013, 12:14 AM
In my testing this looks to be working ok. See the example below tested with ExtJS 4.2.1:

https://fiddle.sencha.com/#fiddle/1p4