PDA

View Full Version : Store in namespace



ironlion
10 Feb 2010, 6:14 PM
This is my store in namespace:


App.stores.Makers = Ext.extend(Ext.data.Store, {
constructor: function(config) {
App.stores.Makers.superclass.constructor.call(this, Ext.apply({
proxy: new Ext.data.HttpProxy({
url: 'serverside/api.php',
method: 'POST'
}),
baseParams: {
task: 'makers'
},
// autoLoad: true,
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: 'makers',
totalProperty: 'totalCount',
fields: [
{
name:'id',
type:'int'
},
'name']
}),
sortInfo: {
field: 'name',
direction: 'ASC'
}
}, config));
}
});
Ext.reg('Makers', App.stores.Makers);


The store works fine with combobox. But when I calling other methods getCount(), getById etc it return nothing.
Also tried WorkingCombo.getStore().getCount(), returns 0.


My question:
How to use default store methods with this?

zachext
10 Feb 2010, 7:27 PM
In your constructor you are referencing EBOM.stores but your namespace appears to be App.stores.

ironlion
10 Feb 2010, 7:31 PM
In your constructor you are referencing EBOM.stores but your namespace appears to be App.stores.

Ok, corrected. But question is still same.

zachext
10 Feb 2010, 8:33 PM
The default store methods should be available. Are you certain the store is loading the json?

Here's an example that should work.


<script type="text/javascript" language="javascript">

Ext.ns("App.stores.Makers");
App.stores.Makers = Ext.extend(Ext.data.Store, {
constructor: function(config) {
App.stores.Makers.superclass.constructor.call(this, Ext.apply({
proxy: new Ext.data.HttpProxy({
url: 'serverside/api.php',
method: 'GET'
}),
storeId:'Makers',
baseParams: {
task: 'makers'
},
// autoLoad: true,
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: 'records',
totalProperty: 'totalCount',
fields: [
{
name:'id',
type:'int'
},
'name']
}),
sortInfo: {
field: 'name',
direction: 'ASC'
}
}, config));
}
});
Ext.reg('Makers', App.stores.Makers);


var cbo={xtype:'combo',id:'WorkingCombo',mode:'local',
store:new App.stores.Makers(),displayField:'name',
listeners:{
render:function(){Ext.StoreMgr.get('Makers').load()}

}}

var button = {xtype:'button',text:'Get Count',handler:function(){Ext.Msg.alert('',Ext.StoreMgr.get('Makers').getCount())}}

Ext.onReady(function() {

new Ext.Container({renderTo:document.body,items:[cbo,button]})


})

</script>

realjax
11 Feb 2010, 2:30 AM
Your code is fine, I just tested it.
Are you sure you are using it correctly ? Create an instance from it etcetera? getting it to load() ?

ironlion
11 Feb 2010, 3:13 PM
Your code is fine, I just tested it.
Are you sure you are using it correctly ? Create an instance from it etcetera? getting it to load() ?


App.stores.Makers.getCount()

App.stores.Makers.getById('1').get('name')

Does above work?

daanlib
11 Feb 2010, 4:12 PM
What realjax means by 'create an instance' is what's going wrong here. Only extending Ext.data.Store doesn't give you an instance. You need an instance of the class to use it in you application. Try the following:


store = new App.stores.Makers({...your config...});
App.stores.Makers.getCount();
App.stores.Makers.getById('1').get('name');